Cleaned up dict.update(single elem dict) code
There's several places in the code where this type of thing exists: form_data.update({'vpnservice_id': vpnservice.id}) better would be this: form_data['vpnservice_id'] = vpnservice.id This type of thing bothers me, so I'm going to clean it up. Also fixed the two cases of: if <some_string>.find(<some_other_string>) != -1: which should clearly use the "in" operator instead. Change-Id: Ic72a5b0a17c211f3949edc69732c1101c24590ec Closes-Bug: 1339849
This commit is contained in:
parent
5323bb1bdf
commit
28e5874eb7
|
@ -699,7 +699,7 @@ class Site(Registry, HorizonComponent):
|
|||
return user_home(user)
|
||||
elif isinstance(user_home, basestring):
|
||||
# Assume we've got a URL if there's a slash in it
|
||||
if user_home.find("/") != -1:
|
||||
if '/' in user_home:
|
||||
return user_home
|
||||
else:
|
||||
mod, func = user_home.rsplit(".", 1)
|
||||
|
|
|
@ -170,7 +170,7 @@ class DynamicSelectWidget(widgets.Select):
|
|||
def render(self, *args, **kwargs):
|
||||
add_item_url = self.get_add_item_url()
|
||||
if add_item_url is not None:
|
||||
self.attrs.update({self._data_add_url_attr: add_item_url})
|
||||
self.attrs[self._data_add_url_attr] = add_item_url
|
||||
return super(DynamicSelectWidget, self).render(*args, **kwargs)
|
||||
|
||||
def get_add_item_url(self):
|
||||
|
|
|
@ -45,7 +45,7 @@ class HTMLElement(object):
|
|||
additional = " ".join(getattr(self, "classes", []))
|
||||
non_empty = [test for test in (defined, default, additional) if test]
|
||||
final_classes = " ".join(non_empty).strip()
|
||||
final_attrs.update({'class': final_classes})
|
||||
final_attrs['class'] = final_classes
|
||||
return final_attrs
|
||||
|
||||
@property
|
||||
|
|
|
@ -578,7 +578,7 @@ class LoadBalancerTests(test.TestCase):
|
|||
self.mox.ReplayAll()
|
||||
|
||||
form_data = data.copy()
|
||||
form_data.update({'pool_id': pool.id})
|
||||
form_data['pool_id'] = pool.id
|
||||
|
||||
res = self.client.post(
|
||||
reverse(self.UPDATEPOOL_PATH, args=(pool.id,)), form_data)
|
||||
|
@ -620,7 +620,7 @@ class LoadBalancerTests(test.TestCase):
|
|||
self.mox.ReplayAll()
|
||||
|
||||
form_data = data.copy()
|
||||
form_data.update({'vip_id': vip.id})
|
||||
form_data['vip_id'] = vip.id
|
||||
|
||||
res = self.client.post(
|
||||
reverse(self.UPDATEVIP_PATH, args=(vip.id,)), form_data)
|
||||
|
@ -662,7 +662,7 @@ class LoadBalancerTests(test.TestCase):
|
|||
self.mox.ReplayAll()
|
||||
|
||||
form_data = data.copy()
|
||||
form_data.update({'member_id': member.id})
|
||||
form_data['member_id'] = member.id
|
||||
|
||||
res = self.client.post(
|
||||
reverse(self.UPDATEMEMBER_PATH, args=(member.id,)), form_data)
|
||||
|
@ -705,7 +705,7 @@ class LoadBalancerTests(test.TestCase):
|
|||
self.mox.ReplayAll()
|
||||
|
||||
form_data = data.copy()
|
||||
form_data.update({'monitor_id': monitor.id})
|
||||
form_data['monitor_id'] = monitor.id
|
||||
|
||||
res = self.client.post(
|
||||
reverse(self.UPDATEMONITOR_PATH, args=(monitor.id,)), form_data)
|
||||
|
|
|
@ -584,7 +584,7 @@ class VPNTests(test.TestCase):
|
|||
self.mox.ReplayAll()
|
||||
|
||||
form_data = data.copy()
|
||||
form_data.update({'vpnservice_id': vpnservice.id})
|
||||
form_data['vpnservice_id'] = vpnservice.id
|
||||
|
||||
res = self.client.post(reverse(
|
||||
self.UPDATEVPNSERVICE_PATH, args=(vpnservice.id,)), form_data)
|
||||
|
@ -630,12 +630,11 @@ class VPNTests(test.TestCase):
|
|||
|
||||
form_data = data.copy()
|
||||
|
||||
form_data.update({'lifetime_units': form_data['lifetime']['units']})
|
||||
form_data.update({'lifetime_value': form_data['lifetime']['value']})
|
||||
form_data.update({'lifetime_units': form_data['lifetime']['units'],
|
||||
'lifetime_value': form_data['lifetime']['value'],
|
||||
'ikepolicy_id': ikepolicy.id})
|
||||
form_data.pop('lifetime')
|
||||
|
||||
form_data.update({'ikepolicy_id': ikepolicy.id})
|
||||
|
||||
res = self.client.post(reverse(
|
||||
self.UPDATEIKEPOLICY_PATH, args=(ikepolicy.id,)), form_data)
|
||||
|
||||
|
@ -680,12 +679,11 @@ class VPNTests(test.TestCase):
|
|||
|
||||
form_data = data.copy()
|
||||
|
||||
form_data.update({'lifetime_units': form_data['lifetime']['units']})
|
||||
form_data.update({'lifetime_value': form_data['lifetime']['value']})
|
||||
form_data.update({'lifetime_units': form_data['lifetime']['units'],
|
||||
'lifetime_value': form_data['lifetime']['value'],
|
||||
'ipsecpolicy_id': ipsecpolicy.id})
|
||||
form_data.pop('lifetime')
|
||||
|
||||
form_data.update({'ipsecpolicy_id': ipsecpolicy.id})
|
||||
|
||||
res = self.client.post(reverse(
|
||||
self.UPDATEIPSECPOLICY_PATH, args=(ipsecpolicy.id,)), form_data)
|
||||
|
||||
|
@ -737,15 +735,15 @@ class VPNTests(test.TestCase):
|
|||
|
||||
form_data = data.copy()
|
||||
|
||||
form_data.update({'dpd_action': form_data['dpd']['action']})
|
||||
form_data.update({'dpd_interval': form_data['dpd']['interval']})
|
||||
form_data.update({'dpd_timeout': form_data['dpd']['timeout']})
|
||||
form_data.update({
|
||||
'dpd_action': form_data['dpd']['action'],
|
||||
'dpd_interval': form_data['dpd']['interval'],
|
||||
'dpd_timeout': form_data['dpd']['timeout'],
|
||||
'peer_cidrs': ", ".join(ipsecsiteconnection['peer_cidrs']),
|
||||
'ipsecsiteconnection_id': ipsecsiteconnection.id,
|
||||
})
|
||||
form_data.pop('dpd')
|
||||
|
||||
form_data['peer_cidrs'] = ", ".join(ipsecsiteconnection['peer_cidrs'])
|
||||
|
||||
form_data.update({'ipsecsiteconnection_id': ipsecsiteconnection.id})
|
||||
|
||||
res = self.client.post(
|
||||
reverse(self.UPDATEVPNCONNECTION_PATH,
|
||||
args=(ipsecsiteconnection.id,)), form_data)
|
||||
|
|
|
@ -177,8 +177,8 @@ class AddIKEPolicyStep(workflows.Step):
|
|||
|
||||
def contribute(self, data, context):
|
||||
context = super(AddIKEPolicyStep, self).contribute(data, context)
|
||||
context.update({'lifetime': {'units': data['lifetime_units'],
|
||||
'value': data['lifetime_value']}})
|
||||
context['lifetime'] = {'units': data['lifetime_units'],
|
||||
'value': data['lifetime_value']}
|
||||
context.pop('lifetime_units')
|
||||
context.pop('lifetime_value')
|
||||
if data:
|
||||
|
@ -274,8 +274,8 @@ class AddIPSecPolicyStep(workflows.Step):
|
|||
|
||||
def contribute(self, data, context):
|
||||
context = super(AddIPSecPolicyStep, self).contribute(data, context)
|
||||
context.update({'lifetime': {'units': data['lifetime_units'],
|
||||
'value': data['lifetime_value']}})
|
||||
context['lifetime'] = {'units': data['lifetime_units'],
|
||||
'value': data['lifetime_value']}
|
||||
context.pop('lifetime_units')
|
||||
context.pop('lifetime_value')
|
||||
if data:
|
||||
|
@ -450,9 +450,9 @@ class AddIPSecSiteConnectionOptionalStep(workflows.Step):
|
|||
def contribute(self, data, context):
|
||||
context = super(
|
||||
AddIPSecSiteConnectionOptionalStep, self).contribute(data, context)
|
||||
context.update({'dpd': {'action': data['dpd_action'],
|
||||
'interval': data['dpd_interval'],
|
||||
'timeout': data['dpd_timeout']}})
|
||||
context['dpd'] = {'action': data['dpd_action'],
|
||||
'interval': data['dpd_interval'],
|
||||
'timeout': data['dpd_timeout']}
|
||||
context.pop('dpd_action')
|
||||
context.pop('dpd_interval')
|
||||
context.pop('dpd_timeout')
|
||||
|
|
Loading…
Reference in New Issue