8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-23 07:23:46 +00:00

Reparation ip search + formatage exact des macs

This commit is contained in:
Gabriel Detraz 2018-11-03 19:24:46 +01:00 committed by chirac
parent a0edac376e
commit d2f80bb39e
3 changed files with 5 additions and 6 deletions

View file

@ -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
validation"""
try:
self.mac_address = str(EUI(self.mac_address))
self.mac_address = str(EUI(self.mac_address, dialect=default_dialect()))
except:
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.filter_macaddress()
self.mac_address = str(EUI(self.mac_address)) or None
if not self.ipv4 or self.type.ip_type != self.ipv4.ip_type:
self.assign_ipv4()
super(Interface, self).clean(*args, **kwargs)

View file

@ -174,7 +174,7 @@ def search_single_word(word, filters, user,
interface__ipv4__ipv4__icontains=word
)
try:
_mac_addr = EUI(word)
_mac_addr = EUI(word, 48)
filter_machines |= Q(interface__mac_address=word)
except AddrFormatError:
pass

View file

@ -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(
machine__user=self
).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