From e1fa749039778f7522ff3027d0a01faa454c57d6 Mon Sep 17 00:00:00 2001 From: Grizzly Date: Sun, 27 Jan 2019 09:39:18 +0000 Subject: [PATCH 1/2] Determine et affiche le vendeur de la mac (wip sur le except) --- machines/models.py | 10 +++++++++ machines/templates/machines/aff_machines.html | 22 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/machines/models.py b/machines/models.py index cdc6d830..d02ee0f7 100644 --- a/machines/models.py +++ b/machines/models.py @@ -1044,6 +1044,16 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model): IPv6Address(prefix_v6).exploded[:20] + IPv6Address(self.id).exploded[20:] ) + @cached_property + def get_vendor(self): + """Retourne le vendeur associé à la mac de l'interface""" + mac = EUI(self.mac_address) + try: + oui = mac.oui + vendor = oui.registration().org + except: + vendor = "Unknown vendor" + return(vendor) def sync_ipv6_dhcpv6(self): """Affecte une ipv6 dhcpv6 calculée à partir de l'id de la machine""" diff --git a/machines/templates/machines/aff_machines.html b/machines/templates/machines/aff_machines.html index 02ec3c91..6001f7ce 100644 --- a/machines/templates/machines/aff_machines.html +++ b/machines/templates/machines/aff_machines.html @@ -92,6 +92,11 @@ with this program; if not, write to the Free Software Foundation, Inc., {{ interface.mac_address }} + IPv4 {{ interface.ipv4 }} @@ -163,6 +168,17 @@ with this program; if not, write to the Free Software Foundation, Inc., + + +
+ +
+ + {% if ipv6_enabled and interface.ipv6 != 'None' %} @@ -217,6 +233,12 @@ with this program; if not, write to the Free Software Foundation, Inc., ipv6_div[i].collapse('hide'); } }); + $("#machines_table").ready(function () { + var vendor_div = [{% for machine in machines_list %}{% for interface in machine.interface_set.all %}{% if interface.get_vendor %}$("#collapseVendor_{{ interface.id }}"), {% endif %}{% endfor %}{% endfor %}]; + for (var i = 0; i < vendor_div.length; i++) { + vendor_div[i].collapse('hide'); + } + }); {% if machines_list.paginator %} From e02456072943bf623b5597180874e5d95f480f30 Mon Sep 17 00:00:00 2001 From: Grizzly Date: Sun, 27 Jan 2019 10:38:43 +0000 Subject: [PATCH 2/2] Meilleur gestion d'erreur --- machines/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/machines/models.py b/machines/models.py index d02ee0f7..75da1317 100644 --- a/machines/models.py +++ b/machines/models.py @@ -44,7 +44,7 @@ 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, default_dialect -from netaddr import mac_bare, EUI, IPSet, IPRange, IPNetwork, IPAddress +from netaddr import mac_bare, EUI, NotRegisteredError, IPSet, IPRange, IPNetwork, IPAddress import preferences.models import users.models @@ -1051,7 +1051,7 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model): try: oui = mac.oui vendor = oui.registration().org - except: + except NotRegisteredError: vendor = "Unknown vendor" return(vendor)