From f55de14401af2a8bc5295f4e9a61022f565e8bdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Thu, 2 Nov 2017 16:06:44 +0000 Subject: [PATCH] Ajoute la recherche dans les chambres --- search/forms.py | 5 +++-- search/templates/search/index.html | 6 +++++- search/views.py | 18 +++++++++++++++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/search/forms.py b/search/forms.py index 23d0acc2..1a40899a 100644 --- a/search/forms.py +++ b/search/forms.py @@ -37,8 +37,9 @@ CHOICES_AFF = ( ('2', 'Factures'), ('3', 'Bannissements'), ('4', 'Accès à titre gracieux'), - ('6', 'Switchs'), - ('5', 'Ports'), + ('5', 'Chambres'), + ('6', 'Ports'), + ('7', 'Switchs'), ) diff --git a/search/templates/search/index.html b/search/templates/search/index.html index c65807fb..c043a22b 100644 --- a/search/templates/search/index.html +++ b/search/templates/search/index.html @@ -48,6 +48,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,

Résultats dans les banissements :

{% include "users/aff_bans.html" with ban_list=bans_list %} {% endif %} + {% if rooms_list %} +

Résultats dans les chambres :

+ {% include "topologie/aff_chambres.html" with room_list=rooms_list %} + {% endif %} {% if switch_ports_list %}

Résultats dans les ports :

{% include "topologie/aff_port.html" with port_list=switch_ports_list %} @@ -56,7 +60,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,

Résultats dans les switchs :

{% include "topologie/aff_switch.html" with switch_list=switches_list %} {% endif %} - {% if not users_list and not machines_list and not factures_list and not whitelists_list and not bans_list and not switch_ports_list and not switches_list%} + {% if not users_list and not machines_list and not factures_list and not whitelists_list and not bans_list and not rooms_list and not switch_ports_list and not switches_list %}

Aucun résultat

{% else %}
(Seulement les {{ max_result }} premiers résultats sont affichés dans chaque catégorie)
diff --git a/search/views.py b/search/views.py index 452030c2..874d5d24 100644 --- a/search/views.py +++ b/search/views.py @@ -35,7 +35,7 @@ from django.contrib.auth.decorators import login_required from django.db.models import Q from users.models import User, Ban, Whitelist from machines.models import Machine, Interface -from topologie.models import Port, Switch +from topologie.models import Port, Switch, Room from cotisations.models import Facture from preferences.models import GeneralOption from search.forms import ( @@ -68,6 +68,7 @@ def get_results(query, request, filters={}): 'factures_list' : Facture.objects.none(), 'bans_list' : Ban.objects.none(), 'whitelists_list': Whitelist.objects.none(), + 'rooms_list': Room.objects.none(), 'switch_ports_list': Port.objects.none(), 'switches_list': Switch.objects.none() } @@ -201,8 +202,19 @@ def get_results(query, request, filters={}): SortTable.USERS_INDEX_WHITE ) - # Switch ports + # Rooms if '5' in aff and request.user.has_perms(('cableur',)): + filter_rooms_list = Q(details__icontains=query) | Q(name__icontains=query) + results['rooms_list'] = Room.objects.filter(filter_rooms_list) + results['rooms_list'] = SortTable.sort( + results['rooms_list'], + request.GET.get('col'), + request.GET.get('order'), + SortTable.TOPOLOGIE_INDEX_ROOM + ) + + # Switch ports + if '6' in aff and request.user.has_perms(('cableur',)): results['switch_ports_list'] = Port.objects.filter(details__icontains=query) results['switch_ports_list'] = SortTable.sort( results['switch_ports_list'], @@ -212,7 +224,7 @@ def get_results(query, request, filters={}): ) # Switches - if '6' in aff and request.user.has_perms(('cableur',)): + if '7' in aff and request.user.has_perms(('cableur',)): results['switches_list'] = Switch.objects.filter(details__icontains=query) results['switches_list'] = SortTable.sort( results['switches_list'],