From db0c9bd2fe2d3553a2d6a617922a338fbf6b0b86 Mon Sep 17 00:00:00 2001 From: chirac Date: Fri, 8 Sep 2017 16:02:11 +0200 Subject: [PATCH] Fix les erreurs de none sur macaddress --- machines/models.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/machines/models.py b/machines/models.py index 1053dd8c..3d146258 100644 --- a/machines/models.py +++ b/machines/models.py @@ -213,7 +213,15 @@ class Interface(models.Model): def mac_bare(self): return str(EUI(self.mac_address, dialect=mac_bare)).lower() + def filter_macaddress(self): + mac_address = str(EUI(self.mac_address)) + if mac_address: + self.mac_address = mac_address + else: + raise ValidationError("La mac donnée est invalide") + def clean(self, *args, **kwargs): + 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() @@ -237,7 +245,7 @@ class Interface(models.Model): self.save() def save(self, *args, **kwargs): - self.mac_address = str(EUI(self.mac_address)) or None + self.filter_macaddress() # On verifie la cohérence en forçant l'extension par la méthode if self.type.ip_type != self.ipv4.ip_type: raise ValidationError("L'ipv4 et le type de la machine ne correspondent pas")