From ee79e21e353e4be00ca1cee45767ac959c20adef Mon Sep 17 00:00:00 2001 From: chirac Date: Sat, 30 Jun 2018 16:19:02 +0000 Subject: [PATCH] =?UTF-8?q?Finition,=20gestion=20du=20renvoie=20du=20profi?= =?UTF-8?q?l=20par=20d=C3=A9faut=20du=20port?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- search/views.py | 4 +-- topologie/models.py | 30 ++++++++++++++------- topologie/templates/topologie/aff_port.html | 2 +- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/search/views.py b/search/views.py index 871515fa..0ae8470b 100644 --- a/search/views.py +++ b/search/views.py @@ -262,9 +262,9 @@ def search_single_word(word, filters, user, ) | Q( related__switch__interface__domain__name__icontains=word ) | Q( - radius__icontains=word + custom_profil__name__icontains=word ) | Q( - vlan_force__name__icontains=word + custom_profil__profil_default__icontains=word ) | Q( details__icontains=word ) diff --git a/topologie/models.py b/topologie/models.py index 79f2cf67..e4a79f74 100644 --- a/topologie/models.py +++ b/topologie/models.py @@ -413,19 +413,29 @@ class Port(AclMixin, RevMixin, models.Model): @cached_property def get_port_profil(self): """Return the config profil for this port""" - if self.custom_profil: - return custom_profil - elif self.related: - return PortProfil.objects.get(profil_default='uplink') - elif self.machine_interface: - if isinstance(self.machine_interface.machine, AccessPoint): - return PortProfil.objects.get(profil_default='access_point') + def profil_or_nothing(profil): + port_profil = PortProfile.objects.filter(profil_default=profil).first() + if port_profil: + return port_profil else: - return PortProfil.objects.get(profil_default='asso_machine') + nothing = PortProfile.objects.filter(profil_default='nothing').first() + if not nothing: + nothing = PortProfile.objects.create(profil_default='nothing', name='nothing', radius_type='NO') + return nothing + + if self.custom_profil: + return self.custom_profil + elif self.related: + return profil_or_nothing('uplink') + elif self.machine_interface: + if hasattr(self.machine_interface.machine, 'accesspoint'): + return profil_or_nothing('access_point') + else: + return profil_or_nothing('asso_machine') elif self.room: - return PortProfil.objects.get(profil_default='room') + return profil_or_nothing('room') else: - return PortProfil.objects.get(profil_default='nothing') + return profil_or_nothing('nothing') @classmethod def get_instance(cls, portid, *_args, **kwargs): diff --git a/topologie/templates/topologie/aff_port.html b/topologie/templates/topologie/aff_port.html index 34130199..85fe901e 100644 --- a/topologie/templates/topologie/aff_port.html +++ b/topologie/templates/topologie/aff_port.html @@ -70,7 +70,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% acl_end %} {% endif %} - {% if not port.custom_profil %}Par défaut{% else %}{{port.custom_profil}}{% endif %} + {% if not port.custom_profil %}Par défaut : {% endif %}{{port.get_port_profil}} {{ port.details }} {% history_button port %}