Commit d2f80bb3 authored by Gabriel Detraz's avatar Gabriel Detraz Committed by chirac

Reparation ip search + formatage exact des macs

parent a0edac37
......@@ -43,7 +43,7 @@ from django.forms import ValidationError
from django.utils import timezone
from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _
from macaddress.fields import MACAddressField
from macaddress.fields import MACAddressField, default_dialect
from netaddr import mac_bare, EUI, IPSet, IPRange, IPNetwork, IPAddress
import preferences.models
......@@ -1099,7 +1099,7 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
""" Tente un formatage mac_bare, si échoue, lève une erreur de
self.mac_address = str(EUI(self.mac_address))
self.mac_address = str(EUI(self.mac_address, dialect=default_dialect()))
raise ValidationError(_("The given MAC address is invalid."))
......@@ -1116,7 +1116,6 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
if not hasattr(self, 'type'):
raise ValidationError(_("The selected IP type is invalid."))
self.mac_address = str(EUI(self.mac_address)) or None
if not self.ipv4 or self.type.ip_type != self.ipv4.ip_type:
super(Interface, self).clean(*args, **kwargs)
......@@ -174,7 +174,7 @@ def search_single_word(word, filters, user,
_mac_addr = EUI(word)
_mac_addr = EUI(word, 48)
filter_machines |= Q(interface__mac_address=word)
except AddrFormatError:
......@@ -616,9 +616,9 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
if access_refresh:
user_ldap.dialupAccess = str(self.has_access())
if mac_refresh:
user_ldap.macs = sorted([str(mac) for mac in Interface.objects.filter(
user_ldap.macs = [str(mac) for mac in Interface.objects.filter(
).values_list('mac_address', flat=True).distinct()])
).values_list('mac_address', flat=True).distinct()]
if group_refresh:
# Need to refresh all groups because we don't know which groups
# were updated during edition of groups and the user may no longer
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 to comment