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"]) ...@@ -37,7 +37,7 @@ add_introspection_rules([], ["firewall\.fields\.MACAddressField"])
def val_alfanum(value): def val_alfanum(value):
"""Validate whether the parameter is a valid alphanumeric 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 ' raise ValidationError(_(u'%s - only letters, numbers, underscores '
'and hyphens are allowed!') % value) 'and hyphens are allowed!') % value)
......
...@@ -44,7 +44,7 @@ class Firewall: ...@@ -44,7 +44,7 @@ class Firewall:
self.RULES_NAT.append(s) self.RULES_NAT.append(s)
def host2vlan(self, host, rule): def host2vlan(self, host, rule):
if rule.foreign_network is None: if not rule.foreign_network:
return return
if self.IPV6 and host.ipv6: if self.IPV6 and host.ipv6:
...@@ -77,7 +77,7 @@ class Firewall: ...@@ -77,7 +77,7 @@ class Firewall:
def fw2vlan(self, rule): def fw2vlan(self, rule):
if rule.foreign_network is None: if not rule.foreign_network:
return return
dport_sport = self.dportsport(rule) dport_sport = self.dportsport(rule)
...@@ -93,7 +93,7 @@ class Firewall: ...@@ -93,7 +93,7 @@ class Firewall:
'LOG_ACC' if rule.accept else 'LOG_DROP')) 'LOG_ACC' if rule.accept else 'LOG_DROP'))
def vlan2vlan(self, l_vlan, rule): def vlan2vlan(self, l_vlan, rule):
if rule.foreign_network is None: if not rule.foreign_network:
return return
dport_sport = self.dportsport(rule) dport_sport = self.dportsport(rule)
......
...@@ -164,7 +164,7 @@ class Host(models.Model): ...@@ -164,7 +164,7 @@ class Host(models.Model):
"address as your own IPv4.")) "address as your own IPv4."))
self.full_clean() self.full_clean()
super(Host, self).save(*args, **kwargs) super(Host, self).save(*args, **kwargs)
if id is None: if not id:
Record(domain=self.vlan.domain, host=self, type='A', Record(domain=self.vlan.domain, host=self, type='A',
owner=self.owner).save() owner=self.owner).save()
if self.ipv6: if self.ipv6:
...@@ -270,14 +270,14 @@ class Record(models.Model): ...@@ -270,14 +270,14 @@ class Record(models.Model):
raise ValidationError(_("Can't specify name for " raise ValidationError(_("Can't specify name for "
"A or AAAA records if host is set!")) "A or AAAA records if host is set!"))
elif self.type == 'CNAME': elif self.type == 'CNAME':
if self.name is None: if not self.name:
raise ValidationError(_("Name must be specified for " raise ValidationError(_("Name must be specified for "
"CNAME records if host is set!")) "CNAME records if host is set!"))
if self.address: if self.address:
raise ValidationError(_("Can't specify address for " raise ValidationError(_("Can't specify address for "
"CNAME records if host is set!")) "CNAME records if host is set!"))
else: # if self.host is None else: # if self.host is None
if self.address is None: if not self.address:
raise ValidationError(_("Address must be specified!")) raise ValidationError(_("Address must be specified!"))
if self.type == 'A': if self.type == 'A':
...@@ -304,10 +304,10 @@ class Record(models.Model): ...@@ -304,10 +304,10 @@ class Record(models.Model):
else: else:
return self.name return self.name
else: # if self.host is None else: # if self.host is None
if not self.name: if self.name:
return unicode(self.domain)
else:
return self.name + '.' + unicode(self.domain) return self.name + '.' + unicode(self.domain)
else:
return unicode(self.domain)
def __get_address(self): def __get_address(self):
if self.host: if self.host:
...@@ -327,7 +327,7 @@ class Record(models.Model): ...@@ -327,7 +327,7 @@ class Record(models.Model):
address = self.__get_address() address = self.__get_address()
if self.host and self.type == 'AAAA' and not self.host.ipv6: if self.host and self.type == 'AAAA' and not self.host.ipv6:
return None return None
elif address is None or name is None: elif not address or not name:
return None return None
else: else:
return {'name': name, 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