Commit 15cff265 by Bach Dániel

firewall: rename ipv4_2_ipv6 to convert_ipv4_to_ipv6

parent 4db5bd68
...@@ -261,11 +261,12 @@ def val_mx(value): ...@@ -261,11 +261,12 @@ def val_mx(value):
"Should be: <priority>:<hostname>")) "Should be: <priority>:<hostname>"))
def ipv4_2_ipv6(ipv6_template, ipv4): def convert_ipv4_to_ipv6(ipv6_template, ipv4):
"""Convert IPv4 address string to IPv6 address string.""" """Convert IPv4 address string to IPv6 address string."""
ipv4 = str(ipv4)
val_ipv4(ipv4) val_ipv4(ipv4)
m = ipv4_re.match(ipv4) m = ipv4_re.match(ipv4)
return (ipv6_template % {'a': int(m.group(1)), return IPAddress(ipv6_template % {'a': int(m.group(1)),
'b': int(m.group(2)), 'b': int(m.group(2)),
'c': int(m.group(3)), 'c': int(m.group(3)),
'd': int(m.group(4))}) 'd': int(m.group(4))})
...@@ -9,9 +9,9 @@ from django.db import models ...@@ -9,9 +9,9 @@ from django.db import models
from django.forms import ValidationError from django.forms import ValidationError
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from firewall.fields import (MACAddressField, val_alfanum, val_reverse_domain, from firewall.fields import (MACAddressField, val_alfanum, val_reverse_domain,
val_ipv6_template, val_ipv6_template, val_domain, val_ipv4,
val_domain, val_ipv4, val_ipv6, val_mx, val_ipv6, val_mx, convert_ipv4_to_ipv6,
ipv4_2_ipv6, IPNetworkField, IPAddressField) IPNetworkField, IPAddressField)
from django.core.validators import MinValueValidator, MaxValueValidator from django.core.validators import MinValueValidator, MaxValueValidator
import django.conf import django.conf
from django.db.models.signals import post_save, post_delete from django.db.models.signals import post_save, post_delete
...@@ -473,7 +473,8 @@ class Host(models.Model): ...@@ -473,7 +473,8 @@ class Host(models.Model):
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
if not self.id and self.ipv6 == "auto": if not self.id and self.ipv6 == "auto":
self.ipv6 = ipv4_2_ipv6(self.vlan.ipv6_template, self.ipv4) self.ipv6 = convert_ipv4_to_ipv6(self.vlan.ipv6_template,
self.ipv4)
self.full_clean() self.full_clean()
super(Host, self).save(*args, **kwargs) super(Host, self).save(*args, **kwargs)
......
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