From fa35818409732ea8e6735566c8148be24a57b62d Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sun, 20 Nov 2016 17:57:10 +0100 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9e=20une=20methode=20mac=5Fbare,=20pour?= =?UTF-8?q?=20renvoyer=20les=20macs=20=20dans=20le=20bon=20format=20ldap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- machines/models.py | 5 ++++- users/models.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/machines/models.py b/machines/models.py index 29e126aa..f7ef3681 100644 --- a/machines/models.py +++ b/machines/models.py @@ -3,7 +3,7 @@ from django.db.models.signals import post_save, post_delete from django.dispatch import receiver from django.forms import ValidationError from macaddress.fields import MACAddressField -from netaddr import EUI +from netaddr import mac_bare, EUI from django.core.validators import MinValueValidator,MaxValueValidator from re2o.settings import MAIN_EXTENSION @@ -86,6 +86,9 @@ class Interface(models.Model): user = self.machine.user return machine.active and user.has_access() + def mac_bare(self): + return str(EUI(self.mac_address, dialect=mac_bare)).lower() + def clean(self, *args, **kwargs): self.mac_address = str(EUI(self.mac_address)) or None if self.ipv4: diff --git a/users/models.py b/users/models.py index 5a9b326f..c966f5c0 100644 --- a/users/models.py +++ b/users/models.py @@ -264,7 +264,7 @@ class User(AbstractBaseUser): if access_refresh: user_ldap.dialupAccess = str(self.has_access()) if mac_refresh: - user_ldap.macs = [inter.mac_address for inter in Interface.objects.filter(machine=Machine.objects.filter(user=self))] + user_ldap.macs = [inter.mac_bare() for inter in Interface.objects.filter(machine=Machine.objects.filter(user=self))] user_ldap.save() def ldap_del(self):