From 6dbfbb894a14a25a0d0f0b5b7cb53b08df3242b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Tue, 19 Sep 2017 20:08:32 +0000 Subject: [PATCH 1/2] =?UTF-8?q?D=C3=A9gage=20filtre=20de=20mac=20valide=20?= =?UTF-8?q?inutile=20et=20incomplet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- machines/forms.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/machines/forms.py b/machines/forms.py index c72026fe..cd4ac87d 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -60,12 +60,6 @@ class EditInterfaceForm(ModelForm): if "machine" in self.fields: self.fields['machine'].queryset = Machine.objects.all().select_related('user') - def clean(self): - data = super(EditInterfaceForm, self).clean() - mac = str(self.data['mac_address']) - if len(''.join(mac.replace("-",":").split(":"))) != 12: - self.add_error('mac_address', "Format de la mac incorrect") - class AddInterfaceForm(EditInterfaceForm): class Meta(EditInterfaceForm.Meta): fields = ['ipv4','mac_address','type','details'] From fb6a522614a4d3960928d73d794d367af2233109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Tue, 19 Sep 2017 20:09:12 +0000 Subject: [PATCH 2/2] Filtre les mac illisibles, non valide et None --- machines/models.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/machines/models.py b/machines/models.py index 7f86d0c0..8eff89fc 100644 --- a/machines/models.py +++ b/machines/models.py @@ -235,10 +235,9 @@ class Interface(models.Model): 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: + try: + self.mac_address = str(EUI(self.mac_address)) + except : raise ValidationError("La mac donnée est invalide") def clean(self, *args, **kwargs):