Commit 4dd3ffd2 by Dudás Ádám

firewall: "if not x" is better than "if x is None" (for maat)

parent 893d31b6
......@@ -37,7 +37,7 @@ add_introspection_rules([], ["firewall\.fields\.MACAddressField"])
def val_alfanum(value):
"""Validate whether the parameter is a valid alphanumeric value."""
if alfanum_re.match(value) is None:
if not alfanum_re.match(value):
raise ValidationError(_(u'%s - only letters, numbers, underscores '
'and hyphens are allowed!') % value)
......
......@@ -44,7 +44,7 @@ class Firewall:
self.RULES_NAT.append(s)
def host2vlan(self, host, rule):
if rule.foreign_network is None:
if not rule.foreign_network:
return
if self.IPV6 and host.ipv6:
......@@ -77,7 +77,7 @@ class Firewall:
def fw2vlan(self, rule):
if rule.foreign_network is None:
if not rule.foreign_network:
return
dport_sport = self.dportsport(rule)
......@@ -93,7 +93,7 @@ class Firewall:
'LOG_ACC' if rule.accept else 'LOG_DROP'))
def vlan2vlan(self, l_vlan, rule):
if rule.foreign_network is None:
if not rule.foreign_network:
return
dport_sport = self.dportsport(rule)
......
......@@ -164,7 +164,7 @@ class Host(models.Model):
"address as your own IPv4."))
self.full_clean()
super(Host, self).save(*args, **kwargs)
if id is None:
if not id:
Record(domain=self.vlan.domain, host=self, type='A',
owner=self.owner).save()
if self.ipv6:
......@@ -270,14 +270,14 @@ class Record(models.Model):
raise ValidationError(_("Can't specify name for "
"A or AAAA records if host is set!"))
elif self.type == 'CNAME':
if self.name is None:
if not self.name:
raise ValidationError(_("Name must be specified for "
"CNAME records if host is set!"))
if self.address:
raise ValidationError(_("Can't specify address for "
"CNAME records if host is set!"))
else: # if self.host is None
if self.address is None:
if not self.address:
raise ValidationError(_("Address must be specified!"))
if self.type == 'A':
......@@ -304,10 +304,10 @@ class Record(models.Model):
else:
return self.name
else: # if self.host is None
if not self.name:
return unicode(self.domain)
else:
if self.name:
return self.name + '.' + unicode(self.domain)
else:
return unicode(self.domain)
def __get_address(self):
if self.host:
......@@ -327,7 +327,7 @@ class Record(models.Model):
address = self.__get_address()
if self.host and self.type == 'AAAA' and not self.host.ipv6:
return None
elif address is None or name is None:
elif not address or not name:
return None
else:
return {'name': name,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment