From f097e7258aefe6d1a129c23048501cc157e71b7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sat, 21 Oct 2017 15:47:42 +0000 Subject: [PATCH 1/9] =?UTF-8?q?Sort=20:=201er=20example=20de=20sort=20sur?= =?UTF-8?q?=20la=20col=20pr=C3=A9nom=20de=20users/index?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- re2o/utils.py | 33 +++++++++++++++++++++++++ templates/buttons/sort.html | 37 ++++++++++++++++++++++++++++ users/templates/users/aff_users.html | 2 +- users/views.py | 8 +++++- 4 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 templates/buttons/sort.html diff --git a/re2o/utils.py b/re2o/utils.py index 8abee181..f6f8cb30 100644 --- a/re2o/utils.py +++ b/re2o/utils.py @@ -139,3 +139,36 @@ def all_active_interfaces_count(): def all_active_assigned_interfaces_count(): """ Version light seulement pour compter""" return all_active_interfaces_count().filter(ipv4__isnull=False) + +class SortTable: + """ Class gathering uselful stuff to sort the colums of a table, according + to the column and order requested. It's used with a dict of possible + values and associated model_fields """ + + # All the possible criteria possible + # The naming convention is based on the URL or the views function + # The syntax is the url value as a key and the associated model field name + # to use as order field in the request. A 'default' might be provided to + # specify what to do if the requested col doesn't match any keys. + USERS_INDEX = { + 'prenom' : 'name', + 'nom' : 'surname', + 'pseudo' : 'pseudo', + 'chamber' : 'room', + 'default' : 'pseudo' + } + + @staticmethod + def sort(request, col, order, criterion): + """ Check if the given values are possible and add .order_by() and + a .reverse() as specified according to those values """ + model_field = criterion.get(col, None) + if not model_field: + model_field = criterion.get('default', None) + if not model_field: + return request + else: + if order == 'desc': + return request.order_by(model_field).reverse() + else: + return request.order_by(model_field) diff --git a/templates/buttons/sort.html b/templates/buttons/sort.html new file mode 100644 index 00000000..48214913 --- /dev/null +++ b/templates/buttons/sort.html @@ -0,0 +1,37 @@ +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + +{% spaceless %} +
+ {{ text }}   +
+ + + + + + +
+
+{% endspaceless %} diff --git a/users/templates/users/aff_users.html b/users/templates/users/aff_users.html index b4ded1f2..aa47f293 100644 --- a/users/templates/users/aff_users.html +++ b/users/templates/users/aff_users.html @@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc., - + diff --git a/users/views.py b/users/views.py index 5b0b3910..17c9c872 100644 --- a/users/views.py +++ b/users/views.py @@ -65,7 +65,7 @@ from machines.models import Machine from preferences.models import OptionalUser, GeneralOption from re2o.views import form -from re2o.utils import all_has_access +from re2o.utils import all_has_access, SortTable def password_change_action(u_form, user, request, req=False): """ Fonction qui effectue le changeemnt de mdp bdd""" @@ -576,6 +576,12 @@ def index(request): options, _created = GeneralOption.objects.get_or_create() pagination_number = options.pagination_number users_list = User.objects.select_related('room').order_by('state', 'name') + users_list = SortTable.sort( + users_list, + request.GET.get('col'), + request.GET.get('order'), + SortTable.USERS_INDEX + ) paginator = Paginator(users_list, pagination_number) page = request.GET.get('page') try: From eb5a340d6c75927fc52fe3255479e998cd290043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sat, 21 Oct 2017 19:31:45 +0000 Subject: [PATCH 2/9] Le sort est compatible avec les autres parametres de l'URL ( 'page=...' ) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ajoute un ta qui permet d'insérer des paramètres dans une URL sans modifier les autres paramètres. --- re2o/templatetags/url_insert_param.py | 100 ++++++++++++++++++++++++++ templates/buttons/sort.html | 6 +- templates/pagination.html | 12 ++-- 3 files changed, 111 insertions(+), 7 deletions(-) create mode 100644 re2o/templatetags/url_insert_param.py diff --git a/re2o/templatetags/url_insert_param.py b/re2o/templatetags/url_insert_param.py new file mode 100644 index 00000000..7e37a71b --- /dev/null +++ b/re2o/templatetags/url_insert_param.py @@ -0,0 +1,100 @@ +# -*- mode: python; coding: utf-8 -*- +# Re2o est un logiciel d'administration développé initiallement au rezometz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# +# Copyright © 2017 Maël Kervella +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +""" +Templatetag used to write a URL (specified or current one) and adding +or inserting specific parameters into the query part without deleting +the other parameters. +""" + +from django import template + +register = template.Library() + + +@register.simple_tag +def url_insert_param(url="", **kwargs): + """ + Return the URL with some specific parameters inserted into the query + part. If a URL has already some parameters, those requested will be + modified if already exisiting or will be added and the other parameters + will stay unmodified. + + **Tag name**:: + + url_insert_param + + **Parameters**: + + url (optional) + The URL to use as a base. The parameters will be added to this URL. + If not specified, it will only return the query part of the URL + ("?a=foo&b=bar" for example). + Example : "https://example.com/bar?foo=0&thing=abc" + + other arguments + Any other key-value argument will be used. The key is considered as + the name of the parameter to insert/modify and the value is the one + used. + Example : q="foo" search="bar" name="johnDoe" + will return as ?&q=foo&search=bar&name=johnDoe + + **Usage**:: + + {% url_insert_param [URL] [param1=val1 [param2=val2 [...]]] %} + + **Example**:: + + {% url_insert_param a=0 b="bar" %} + return "?a=0&b=bar" + + {% url_insert_param "url.net/foo.html" a=0 b="bar" %} + return "url.net/foo.html?a=0&b=bar" + + {% url_insert_param "url.net/foo.html?c=keep" a=0 b="bar" %} + return "url.net/foo.html?c=keep&a=0&b=bar" + + {% url_insert_param "url.net/foo.html?a=del" a=0 b="bar" %} + return "url.net/foo.html?a=0&b=bar" + + {% url_insert_param "url.net/foo.html?a=del&c=keep" a=0 b="bar" %} + return "url.net/foo.hmtl?a=0&c=keep&b=bar" + """ + + # Get existing parameters in the url + params = {} + if '?' in url: + url, params = url.split('?', maxsplit=1) + params = { + p[:p.find('=')]: p[p.find('=')+1:] for p in params.split('&') + } + + # Add the request parameters to the list of parameters + for key, value in kwargs.items(): + params[key] = value + + # Write the url + url += '?' + for param, value in params.items(): + url += str(param) + '=' + str(value) + '&' + + # Remove the last '&' (or '?' if no parameters) + return url[:-1] diff --git a/templates/buttons/sort.html b/templates/buttons/sort.html index 48214913..35c2646b 100644 --- a/templates/buttons/sort.html +++ b/templates/buttons/sort.html @@ -22,14 +22,16 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. {% endcomment %} +{% load url_insert_param %} + {% spaceless %}
{{ text }}  
- + - +
diff --git a/templates/pagination.html b/templates/pagination.html index ba90fe13..7ebd26c1 100644 --- a/templates/pagination.html +++ b/templates/pagination.html @@ -22,20 +22,22 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. {% endcomment %} +{% load url_insert_param %} + From 75c586707b87b2e1cc961131b11a2160cfb453a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sat, 21 Oct 2017 21:45:21 +0000 Subject: [PATCH 3/9] Ajoute les sorts sur les bans et les whitelists --- re2o/utils.py | 24 ++++++++++++++++++----- users/templates/users/aff_bans.html | 8 ++++---- users/templates/users/aff_users.html | 8 ++++---- users/templates/users/aff_whitelists.html | 8 ++++---- users/views.py | 18 +++++++++++++---- 5 files changed, 45 insertions(+), 21 deletions(-) diff --git a/re2o/utils.py b/re2o/utils.py index f6f8cb30..28d6cf0d 100644 --- a/re2o/utils.py +++ b/re2o/utils.py @@ -151,11 +151,25 @@ class SortTable: # to use as order field in the request. A 'default' might be provided to # specify what to do if the requested col doesn't match any keys. USERS_INDEX = { - 'prenom' : 'name', - 'nom' : 'surname', - 'pseudo' : 'pseudo', - 'chamber' : 'room', - 'default' : 'pseudo' + 'name': 'name', + 'surname': 'surname', + 'pseudo': 'pseudo', + 'room': 'room', + 'default': 'pseudo' + } + USERS_INDEX_BAN = { + 'user': 'user__pseudo', + 'reason': 'raison', + 'start': 'date_start', + 'end': 'date_end', + 'default': 'date_end' + } + USERS_INDEX_WHITE = { + 'user': 'user__pseudo', + 'reason': 'raison', + 'start': 'date_start', + 'end': 'date_end', + 'default': 'date_end' } @staticmethod diff --git a/users/templates/users/aff_bans.html b/users/templates/users/aff_bans.html index 693a7539..bb9c3485 100644 --- a/users/templates/users/aff_bans.html +++ b/users/templates/users/aff_bans.html @@ -29,10 +29,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Prénom{% include "buttons/sort.html" with col="prenom" text="Prénom" %} Nom Pseudo Chambre
- - - - + + + + diff --git a/users/templates/users/aff_users.html b/users/templates/users/aff_users.html index aa47f293..ad39ea38 100644 --- a/users/templates/users/aff_users.html +++ b/users/templates/users/aff_users.html @@ -29,10 +29,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
UtilisateurRaisonDate de débutDate de fin{% include "buttons/sort.html" with col="user" text="Utilisateur" %}{% include "buttons/sort.html" with col="reason" text="Raison" %}{% include "buttons/sort.html" with col="start" text="Date de début" %}{% include "buttons/sort.html" with col="end" text="Date de fin" %}
- - - - + + + + diff --git a/users/templates/users/aff_whitelists.html b/users/templates/users/aff_whitelists.html index 6665ad27..d8c857a1 100644 --- a/users/templates/users/aff_whitelists.html +++ b/users/templates/users/aff_whitelists.html @@ -29,10 +29,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% include "buttons/sort.html" with col="prenom" text="Prénom" %}NomPseudoChambre{% include "buttons/sort.html" with col="name" text="Prénom" %}{% include "buttons/sort.html" with col="surname" text="Nom" %}{% include "buttons/sort.html" with col="pseudo" text="Pseudo" %}{% include "buttons/sort.html" with col="room" text="Chambre" %} Fin de cotisation le Connexion Profil
- - - - + + + + diff --git a/users/views.py b/users/views.py index 17c9c872..84b9e26d 100644 --- a/users/views.py +++ b/users/views.py @@ -601,8 +601,13 @@ def index_ban(request): """ Affiche l'ensemble des ban, need droit cableur """ options, _created = GeneralOption.objects.get_or_create() pagination_number = options.pagination_number - ban_list = Ban.objects.order_by('date_start')\ - .select_related('user').reverse() + ban_list = Ban.objects.select_related('user') + ban_list = SortTable.sort( + ban_list, + request.GET.get('col'), + request.GET.get('order'), + SortTable.USERS_INDEX_BAN + ) paginator = Paginator(ban_list, pagination_number) page = request.GET.get('page') try: @@ -622,8 +627,13 @@ def index_white(request): """ Affiche l'ensemble des whitelist, need droit cableur """ options, _created = GeneralOption.objects.get_or_create() pagination_number = options.pagination_number - white_list = Whitelist.objects.select_related('user')\ - .order_by('date_start') + white_list = Whitelist.objects.select_related('user') + white_list = SortTable.sort( + white_list, + request.GET.get('col'), + request.GET.get('order'), + SortTable.USERS_INDEX_BAN + ) paginator = Paginator(white_list, pagination_number) page = request.GET.get('page') try: From 719f70828666482b90a9229e44b9ac92827f78bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sun, 22 Oct 2017 00:33:44 +0000 Subject: [PATCH 4/9] Ajout du sort dans topo, logs, machines, cotisations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ajout du sort sur les colones où ça avait un minimum de sens et où le sort était basé sur des ORDER_BY de BDD. Peut être certaines colones n'avaient pas besoin d'être triées mais tant que c'est possible et pas illogique pourquoi ne pas le faire ? --- .../cotisations/aff_cotisations.html | 6 +-- .../templates/cotisations/control.html | 12 ++--- cotisations/views.py | 25 ++++++--- logs/templates/logs/aff_stats_logs.html | 4 +- logs/templates/logs/aff_summary.html | 2 +- logs/views.py | 19 +++++-- machines/templates/machines/aff_machines.html | 4 +- machines/views.py | 11 +++- re2o/utils.py | 54 +++++++++++++++++++ .../templates/topologie/aff_chambres.html | 2 +- topologie/templates/topologie/aff_port.html | 12 ++--- topologie/templates/topologie/aff_stacks.html | 6 +-- topologie/templates/topologie/aff_switch.html | 12 ++--- topologie/views.py | 37 +++++++++---- 14 files changed, 153 insertions(+), 53 deletions(-) diff --git a/cotisations/templates/cotisations/aff_cotisations.html b/cotisations/templates/cotisations/aff_cotisations.html index e1ce251e..b9548a74 100644 --- a/cotisations/templates/cotisations/aff_cotisations.html +++ b/cotisations/templates/cotisations/aff_cotisations.html @@ -29,11 +29,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
UtilisateurRaisonDate de débutDate de fin{% include "buttons/sort.html" with col="user" text="Utilisateur" %}{% include "buttons/sort.html" with col="reason" text="Raison" %}{% include "buttons/sort.html" with col="start" text="Date de début" %}{% include "buttons/sort.html" with col="end" text="Date de fin" %}
- + - - + + diff --git a/cotisations/templates/cotisations/control.html b/cotisations/templates/cotisations/control.html index 1ccb804f..3282e29e 100644 --- a/cotisations/templates/cotisations/control.html +++ b/cotisations/templates/cotisations/control.html @@ -40,14 +40,14 @@ with this program; if not, write to the Free Software Foundation, Inc., - - + + - - - - + + + + {% for form in controlform.forms %} diff --git a/cotisations/views.py b/cotisations/views.py index 4e2c5304..f0481996 100644 --- a/cotisations/views.py +++ b/cotisations/views.py @@ -40,6 +40,7 @@ from users.models import User from re2o.settings import LOGO_PATH from re2o import settings from re2o.views import form +from re2o.utils import SortTable from preferences.models import OptionalUser, AssoOption, GeneralOption from .models import Facture, Article, Vente, Paiement, Banque from .forms import NewFactureForm, TrezEditFactureForm, EditFactureForm @@ -519,7 +520,13 @@ def control(request): factures.Case à cocher, pratique""" options, _created = GeneralOption.objects.get_or_create() pagination_number = options.pagination_number - facture_list = Facture.objects.order_by('date').reverse() + facture_list = Facture.objects.select_related('user').select_related('paiement') + facture_list = SortTable.sort( + facture_list, + request.GET.get('col'), + request.GET.get('order'), + SortTable.COTISATIONS_CONTROL + ) controlform_set = modelformset_factory( Facture, fields=('control', 'valid'), @@ -533,11 +540,7 @@ def control(request): facture_list = paginator.page(1) except EmptyPage: facture_list = paginator.page(paginator.num.pages) - page_query = Facture.objects.order_by('date').select_related('user')\ - .select_related('paiement').reverse().filter( - id__in=[facture.id for facture in facture_list] - ) - controlform = controlform_set(request.POST or None, queryset=page_query) + controlform = controlform_set(request.POST or None, queryset=facture_list.object_list) if controlform.is_valid(): with transaction.atomic(), reversion.create_revision(): controlform.save() @@ -586,8 +589,14 @@ def index(request): """Affiche l'ensemble des factures, pour les cableurs et +""" options, _created = GeneralOption.objects.get_or_create() pagination_number = options.pagination_number - facture_list = Facture.objects.order_by('date').select_related('user')\ - .select_related('paiement').prefetch_related('vente_set').reverse() + facture_list = Facture.objects.select_related('user')\ + .select_related('paiement').prefetch_related('vente_set') + facture_list = SortTable.sort( + facture_list, + request.GET.get('col'), + request.GET.get('order'), + SortTable.COTISATIONS_INDEX + ) paginator = Paginator(facture_list, pagination_number) page = request.GET.get('page') try: diff --git a/logs/templates/logs/aff_stats_logs.html b/logs/templates/logs/aff_stats_logs.html index 35504144..b0fa2b14 100644 --- a/logs/templates/logs/aff_stats_logs.html +++ b/logs/templates/logs/aff_stats_logs.html @@ -33,8 +33,8 @@ with this program; if not, write to the Free Software Foundation, Inc., - - + + diff --git a/logs/templates/logs/aff_summary.html b/logs/templates/logs/aff_summary.html index 9b791dfd..a00c4e27 100644 --- a/logs/templates/logs/aff_summary.html +++ b/logs/templates/logs/aff_summary.html @@ -31,7 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Utilisateur{% include "buttons/sort.html" with col='user' text='Utilisateur' %} Designation Prix totalMoyen de paiementDate{% include "buttons/sort.html" with col='paiement' text='Moyen de paiement' %}{% include "buttons/sort.html" with col='date' text='Date' %}
ProfilNomPrénom{% include "buttons/sort.html" with col='name' text='Nom' %}{% include "buttons/sort.html" with col='surname' text='Prénom' %} Designation Prix totalMoyen de paiementDateValiditéControle trésorier{% include "buttons/sort.html" with col='paiement' text='Moyen de paiement' %}{% include "buttons/sort.html" with col='date' text='Date' %}{% include "buttons/sort.html" with col='valid' text='Valide' %}{% include "buttons/sort.html" with col='control' text='Contrôlée' %}
Objet modifié Type de l'objetModification parDate de modification{% include "buttons/sort.html" with col='author' text='Modification par' %}{% include "buttons/sort.html" with col='date' text='Date de modification' %} Commentaire
- + diff --git a/logs/views.py b/logs/views.py index e21d4de6..d14dac68 100644 --- a/logs/views.py +++ b/logs/views.py @@ -57,7 +57,7 @@ from preferences.models import GeneralOption from re2o.views import form from re2o.utils import all_whitelisted, all_baned, all_has_access, all_adherent from re2o.utils import all_active_assigned_interfaces_count -from re2o.utils import all_active_interfaces_count +from re2o.utils import all_active_interfaces_count, SortTable STATS_DICT = { 0: ["Tout", 36], @@ -83,7 +83,13 @@ def index(request): content_type__in=ContentType.objects.filter( model__in=content_type_filter ) - ).order_by('revision__date_created').reverse().select_related('revision') + ).select_related('revision') + versions = SortTable.sort( + versions, + request.GET.get('col'), + request.GET.get('order'), + SortTable.LOGS_INDEX + ) paginator = Paginator(versions, pagination_number) page = request.GET.get('page') try: @@ -129,9 +135,14 @@ def stats_logs(request): classés par date croissante, en vrac""" options, _created = GeneralOption.objects.get_or_create() pagination_number = options.pagination_number - revisions = Revision.objects.all().order_by('date_created')\ - .reverse().select_related('user')\ + revisions = Revision.objects.all().select_related('user')\ .prefetch_related('version_set__object') + revisions = SortTable.sort( + revisions, + request.GET.get('col'), + request.GET.get('order'), + SortTable.LOGS_STATS_LOGS + ) paginator = Paginator(revisions, pagination_number) page = request.GET.get('page') try: diff --git a/machines/templates/machines/aff_machines.html b/machines/templates/machines/aff_machines.html index 80e887d2..93720997 100644 --- a/machines/templates/machines/aff_machines.html +++ b/machines/templates/machines/aff_machines.html @@ -35,7 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc., - + @@ -44,7 +44,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% for machine in machines_list %}
Date{% include "buttons/sort.html" with col='date' text='Date' %} Modification
Nom DNS{% include "buttons/sort.html" with col='name' text='Nom DNS' %} Type MAC IP
- {{ machine.name }} + {{ machine.name|default:'Pas de nom' }} {{ machine.user }} diff --git a/machines/views.py b/machines/views.py index 1271e277..2f533de1 100644 --- a/machines/views.py +++ b/machines/views.py @@ -114,7 +114,8 @@ from preferences.models import GeneralOption, OptionalMachine from re2o.utils import ( all_active_assigned_interfaces, all_has_access, - filter_active_interfaces + filter_active_interfaces, + SortTable ) from re2o.views import form @@ -885,7 +886,13 @@ def del_nas(request): def index(request): options, created = GeneralOption.objects.get_or_create() pagination_large_number = options.pagination_large_number - machines_list = Machine.objects.select_related('user').prefetch_related('interface_set__domain__extension').prefetch_related('interface_set__ipv4__ip_type').prefetch_related('interface_set__type__ip_type__extension').prefetch_related('interface_set__domain__related_domain__extension').order_by('pk') + machines_list = Machine.objects.select_related('user').prefetch_related('interface_set__domain__extension').prefetch_related('interface_set__ipv4__ip_type').prefetch_related('interface_set__type__ip_type__extension').prefetch_related('interface_set__domain__related_domain__extension') + machines_list = SortTable.sort( + machines_list, + request.GET.get('col'), + request.GET.get('order'), + SortTable.MACHINES_INDEX + ) paginator = Paginator(machines_list, pagination_large_number) page = request.GET.get('page') try: diff --git a/re2o/utils.py b/re2o/utils.py index 28d6cf0d..369bc058 100644 --- a/re2o/utils.py +++ b/re2o/utils.py @@ -171,6 +171,60 @@ class SortTable: 'end': 'date_end', 'default': 'date_end' } + MACHINES_INDEX = { + 'name': 'name', + 'default': 'pk' + } + COTISATIONS_INDEX = { + 'user': 'user__pseudo', + 'paiement': 'paiement__moyen', + 'date': 'date', + 'default': 'date' + } + COTISATIONS_CONTROL = { + 'name': 'user__name', + 'surname': 'user__surname', + 'paiement': 'paiement', + 'date': 'date', + 'valid': 'valid', + 'control': 'control', + 'default': 'date' + } + TOPOLOGIE_INDEX = { + 'dns': 'switch_interface__domain__name', + 'ip': 'switch_interface__ipv4__ipv4', + 'loc': 'location', + 'ports': 'number', + 'stack': 'stack__name', + 'default': 'switch_interface__domain__name' + } + TOPOLOGIE_INDEX_PORT = { + 'port': 'port', + 'room': 'room__name', + 'interface': 'machine_interface__domain__name', + 'related': 'related__switch__name', + 'radius': 'radius', + 'vlan': 'vlan_force__name', + 'default': 'port' + } + TOPOLOGIE_INDEX_ROOM = { + 'name': 'name', + 'default': 'name' + } + TOPOLOGIE_INDEX_STACK = { + 'name': 'name', + 'id': 'stack_id', + 'default': 'stack_id' + } + LOGS_INDEX = { + 'date': 'revision__date_created', + 'default': 'revision__date_created' + } + LOGS_STATS_LOGS = { + 'author': 'user__name', + 'date': 'date_created', + 'default': 'date_created' + } @staticmethod def sort(request, col, order, criterion): diff --git a/topologie/templates/topologie/aff_chambres.html b/topologie/templates/topologie/aff_chambres.html index d3393fc2..8ac3e5d8 100644 --- a/topologie/templates/topologie/aff_chambres.html +++ b/topologie/templates/topologie/aff_chambres.html @@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc., - + diff --git a/topologie/templates/topologie/aff_port.html b/topologie/templates/topologie/aff_port.html index 609d4349..16b4f258 100644 --- a/topologie/templates/topologie/aff_port.html +++ b/topologie/templates/topologie/aff_port.html @@ -25,12 +25,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Chambre{% include "buttons/sort.html" with col='name' text='Chambre' %} Commentaire
- - - - - - + + + + + + diff --git a/topologie/templates/topologie/aff_stacks.html b/topologie/templates/topologie/aff_stacks.html index 586fd90a..b3ac49ba 100644 --- a/topologie/templates/topologie/aff_stacks.html +++ b/topologie/templates/topologie/aff_stacks.html @@ -25,9 +25,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
PortRoomInterface machineRelatedRadiusVlan forcé{% include "buttons/sort.html" with col='port' text='Port' %}{% include "buttons/sort.html" with col='room' text='Room' %}{% include "buttons/sort.html" with col='interface' text='Interface machine' %}{% include "buttons/sort.html" with col='related' text='Related' %}{% include "buttons/sort.html" with col='radius' text='Radius' %}{% include "buttons/sort.html" with col='vlan' text='Vlan forcé' %} Détails
- - - + + + diff --git a/topologie/templates/topologie/aff_switch.html b/topologie/templates/topologie/aff_switch.html index 611e6c39..894e89a4 100644 --- a/topologie/templates/topologie/aff_switch.html +++ b/topologie/templates/topologie/aff_switch.html @@ -25,12 +25,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
StackIDDetails{% include "buttons/sort.html" with col='name' text='Stack' %}{% include "buttons/sort.html" with col='id' text='ID' %}Détails Membres
- - - - - - + + + + + + diff --git a/topologie/views.py b/topologie/views.py index 5eb2de74..e4f928be 100644 --- a/topologie/views.py +++ b/topologie/views.py @@ -49,7 +49,7 @@ from topologie.models import Switch, Port, Room, Stack from topologie.forms import EditPortForm, NewSwitchForm, EditSwitchForm from topologie.forms import AddPortForm, EditRoomForm, StackForm from users.views import form - +from re2o.utils import SortTable from machines.forms import DomainForm, NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm from machines.views import generate_ipv4_mbf_param from preferences.models import AssoOption, GeneralOption @@ -59,15 +59,17 @@ from preferences.models import AssoOption, GeneralOption @permission_required('cableur') def index(request): """ Vue d'affichage de tous les swicthes""" - switch_list = Switch.objects.order_by( - 'stack', - 'stack_member_id', - 'location' - )\ + switch_list = Switch.objects\ .select_related('switch_interface__domain__extension')\ .select_related('switch_interface__ipv4')\ .select_related('switch_interface__domain')\ .select_related('stack') + switch_list = SortTable.sort( + switch_list, + request.GET.get('col'), + request.GET.get('order'), + SortTable.TOPOLOGIE_INDEX + ) return render(request, 'topologie/index.html', { 'switch_list': switch_list }) @@ -137,8 +139,13 @@ def index_port(request, switch_id): .select_related('machine_interface__domain__extension')\ .select_related('machine_interface__machine__user')\ .select_related('related__switch__switch_interface__domain__extension')\ - .select_related('switch')\ - .order_by('port') + .select_related('switch') + port_list = SortTable.sort( + port_list, + request.GET.get('col'), + request.GET.get('order'), + SortTable.TOPOLOGIE_INDEX_PORT + ) return render(request, 'topologie/index_p.html', { 'port_list': port_list, 'id_switch': switch_id, @@ -151,6 +158,12 @@ def index_port(request, switch_id): def index_room(request): """ Affichage de l'ensemble des chambres""" room_list = Room.objects.order_by('name') + room_list = SortTable.sort( + room_list, + request.GET.get('col'), + request.GET.get('order'), + SortTable.TOPOLOGIE_INDEX_ROOM + ) options, _created = GeneralOption.objects.get_or_create() pagination_number = options.pagination_number paginator = Paginator(room_list, pagination_number) @@ -172,8 +185,14 @@ def index_room(request): @permission_required('infra') def index_stack(request): """Affichage de la liste des stacks (affiche l'ensemble des switches)""" - stack_list = Stack.objects.order_by('name')\ + stack_list = Stack.objects\ .prefetch_related('switch_set__switch_interface__domain__extension') + stack_list = SortTable.sort( + stack_list, + request.GET.get('col'), + request.GET.get('order'), + SortTable.TOPOLOGIE_INDEX_STACK + ) return render(request, 'topologie/index_stack.html', { 'stack_list': stack_list }) From aae9370a55ee6c10395251351581e8d38b9469d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sun, 22 Oct 2017 00:39:25 +0000 Subject: [PATCH 5/9] Supprime le sort sur la colone raison des ban et whitelist (aucun sens) --- re2o/utils.py | 2 -- users/templates/users/aff_bans.html | 2 +- users/templates/users/aff_whitelists.html | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/re2o/utils.py b/re2o/utils.py index 369bc058..adf51ff0 100644 --- a/re2o/utils.py +++ b/re2o/utils.py @@ -159,14 +159,12 @@ class SortTable: } USERS_INDEX_BAN = { 'user': 'user__pseudo', - 'reason': 'raison', 'start': 'date_start', 'end': 'date_end', 'default': 'date_end' } USERS_INDEX_WHITE = { 'user': 'user__pseudo', - 'reason': 'raison', 'start': 'date_start', 'end': 'date_end', 'default': 'date_end' diff --git a/users/templates/users/aff_bans.html b/users/templates/users/aff_bans.html index bb9c3485..3b4b66c1 100644 --- a/users/templates/users/aff_bans.html +++ b/users/templates/users/aff_bans.html @@ -30,7 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc., - + diff --git a/users/templates/users/aff_whitelists.html b/users/templates/users/aff_whitelists.html index d8c857a1..28b8537f 100644 --- a/users/templates/users/aff_whitelists.html +++ b/users/templates/users/aff_whitelists.html @@ -30,7 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc., - + From f139b5b2c4c1627fdbce99c6541cfc7ecde46eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sun, 22 Oct 2017 01:37:27 +0000 Subject: [PATCH 6/9] Sort : support des order_by sur plusieurs fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit et delete de deux order_by oublié dans les views --- re2o/utils.py | 126 ++++++++++++++++++++++----------------------- topologie/views.py | 2 +- users/views.py | 2 +- 3 files changed, 65 insertions(+), 65 deletions(-) diff --git a/re2o/utils.py b/re2o/utils.py index adf51ff0..5c95c47a 100644 --- a/re2o/utils.py +++ b/re2o/utils.py @@ -145,96 +145,96 @@ class SortTable: to the column and order requested. It's used with a dict of possible values and associated model_fields """ - # All the possible criteria possible + # All the possible possible values # The naming convention is based on the URL or the views function - # The syntax is the url value as a key and the associated model field name - # to use as order field in the request. A 'default' might be provided to - # specify what to do if the requested col doesn't match any keys. + # The syntax to describe the sort to apply is a dict where the keys are + # the url value and the values are a list of model field name to use to + # order the request. They are applied in the order they are given. + # A 'default' might be provided to specify what to do if the requested col + # doesn't match any keys. USERS_INDEX = { - 'name': 'name', - 'surname': 'surname', - 'pseudo': 'pseudo', - 'room': 'room', - 'default': 'pseudo' + 'name': ['name'], + 'surname': ['surname'], + 'pseudo': ['pseudo'], + 'room': ['room'], + 'default': ['state', 'pseudo'] } USERS_INDEX_BAN = { - 'user': 'user__pseudo', - 'start': 'date_start', - 'end': 'date_end', - 'default': 'date_end' + 'user': ['user__pseudo'], + 'start': ['date_start'], + 'end': ['date_end'], + 'default': ['-date_end'] } USERS_INDEX_WHITE = { - 'user': 'user__pseudo', - 'start': 'date_start', - 'end': 'date_end', - 'default': 'date_end' + 'user': ['user__pseudo'], + 'start': ['date_start'], + 'end': ['date_end'], + 'default': ['-date_end'] } MACHINES_INDEX = { - 'name': 'name', - 'default': 'pk' + 'name': ['name'], + 'default': ['pk'] } COTISATIONS_INDEX = { - 'user': 'user__pseudo', - 'paiement': 'paiement__moyen', - 'date': 'date', - 'default': 'date' + 'user': ['user__pseudo'], + 'paiement': ['paiement__moyen'], + 'date': ['date'], + 'default': ['-date'] } COTISATIONS_CONTROL = { - 'name': 'user__name', - 'surname': 'user__surname', - 'paiement': 'paiement', - 'date': 'date', - 'valid': 'valid', - 'control': 'control', - 'default': 'date' + 'name': ['user__name'], + 'surname': ['user__surname'], + 'paiement': ['paiement'], + 'date': ['date'], + 'valid': ['valid'], + 'control': ['control'], + 'default': ['-date'] } TOPOLOGIE_INDEX = { - 'dns': 'switch_interface__domain__name', - 'ip': 'switch_interface__ipv4__ipv4', - 'loc': 'location', - 'ports': 'number', - 'stack': 'stack__name', - 'default': 'switch_interface__domain__name' + 'dns': ['switch_interface__domain__name'], + 'ip': ['switch_interface__ipv4__ipv4'], + 'loc': ['location'], + 'ports': ['number'], + 'stack': ['stack__name'], + 'default': ['location', 'stack', 'stack_member_id'] } TOPOLOGIE_INDEX_PORT = { - 'port': 'port', - 'room': 'room__name', - 'interface': 'machine_interface__domain__name', - 'related': 'related__switch__name', - 'radius': 'radius', - 'vlan': 'vlan_force__name', - 'default': 'port' + 'port': ['port'], + 'room': ['room__name'], + 'interface': ['machine_interface__domain__name'], + 'related': ['related__switch__name'], + 'radius': ['radius'], + 'vlan': ['vlan_force__name'], + 'default': ['port'] } TOPOLOGIE_INDEX_ROOM = { - 'name': 'name', - 'default': 'name' + 'name': ['name'], + 'default': ['name'] } TOPOLOGIE_INDEX_STACK = { - 'name': 'name', - 'id': 'stack_id', - 'default': 'stack_id' + 'name': ['name'], + 'id': ['stack_id'], + 'default': ['stack_id'], } LOGS_INDEX = { - 'date': 'revision__date_created', - 'default': 'revision__date_created' + 'date': ['revision__date_created'], + 'default': ['-revision__date_created'], } LOGS_STATS_LOGS = { - 'author': 'user__name', - 'date': 'date_created', - 'default': 'date_created' + 'author': ['user__name'], + 'date': ['date_created'], + 'default': ['-date_created'] } @staticmethod - def sort(request, col, order, criterion): + def sort(request, col, order, values): """ Check if the given values are possible and add .order_by() and a .reverse() as specified according to those values """ - model_field = criterion.get(col, None) - if not model_field: - model_field = criterion.get('default', None) - if not model_field: - return request + fields = values.get(col, None) + if not fields: + fields = values.get('default', []) + request = request.order_by(*fields) + if order == 'desc': + return request.reverse() else: - if order == 'desc': - return request.order_by(model_field).reverse() - else: - return request.order_by(model_field) + return request diff --git a/topologie/views.py b/topologie/views.py index e4f928be..dec681b6 100644 --- a/topologie/views.py +++ b/topologie/views.py @@ -157,7 +157,7 @@ def index_port(request, switch_id): @permission_required('cableur') def index_room(request): """ Affichage de l'ensemble des chambres""" - room_list = Room.objects.order_by('name') + room_list = Room.objects room_list = SortTable.sort( room_list, request.GET.get('col'), diff --git a/users/views.py b/users/views.py index 84b9e26d..316c85ea 100644 --- a/users/views.py +++ b/users/views.py @@ -575,7 +575,7 @@ def index(request): """ Affiche l'ensemble des users, need droit cableur """ options, _created = GeneralOption.objects.get_or_create() pagination_number = options.pagination_number - users_list = User.objects.select_related('room').order_by('state', 'name') + users_list = User.objects.select_related('room') users_list = SortTable.sort( users_list, request.GET.get('col'), From c45357c6f4622f9bcabb5513ada86ae492615ddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sun, 22 Oct 2017 02:28:40 +0000 Subject: [PATCH 7/9] =?UTF-8?q?Sort=20:=20Les=20fl=C3=A8ches=20restent=20c?= =?UTF-8?q?oll=C3=A9es=20et=20centr=C3=A9es=20m=C3=AAme=20si=20titre=20mul?= =?UTF-8?q?tiligne?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/buttons/sort.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/buttons/sort.html b/templates/buttons/sort.html index 35c2646b..7fe59784 100644 --- a/templates/buttons/sort.html +++ b/templates/buttons/sort.html @@ -26,8 +26,8 @@ with this program; if not, write to the Free Software Foundation, Inc., {% spaceless %}
- {{ text }}   -
+ {{ text }}  +
From a87cbb7b7e148cd3e5efd78639f53d4ad68947d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sun, 22 Oct 2017 15:48:35 +0000 Subject: [PATCH 8/9] =?UTF-8?q?Ajout=20de=20prefix=20sur=20tous=20les=20ta?= =?UTF-8?q?bleaux=20pour=20les=20diff=C3=A9rencier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cotisations/aff_cotisations.html | 6 +- .../templates/cotisations/control.html | 12 +-- logs/templates/logs/aff_stats_logs.html | 4 +- logs/templates/logs/aff_summary.html | 2 +- machines/templates/machines/aff_machines.html | 2 +- re2o/utils.py | 74 +++++++++---------- templates/buttons/sort.html | 11 +++ .../templates/topologie/aff_chambres.html | 2 +- topologie/templates/topologie/aff_port.html | 12 +-- topologie/templates/topologie/aff_stacks.html | 4 +- topologie/templates/topologie/aff_switch.html | 10 +-- users/templates/users/aff_bans.html | 6 +- users/templates/users/aff_users.html | 8 +- users/templates/users/aff_whitelists.html | 6 +- 14 files changed, 85 insertions(+), 74 deletions(-) diff --git a/cotisations/templates/cotisations/aff_cotisations.html b/cotisations/templates/cotisations/aff_cotisations.html index b9548a74..59d558bf 100644 --- a/cotisations/templates/cotisations/aff_cotisations.html +++ b/cotisations/templates/cotisations/aff_cotisations.html @@ -29,11 +29,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
DnsIpv4LocalisationPortsStackid interne Stack{% include "buttons/sort.html" with col='dns' text='Dns' %}{% include "buttons/sort.html" with col='ip' text='Ipv4' %}{% include "buttons/sort.html" with col='loc' text='Localisation' %}{% include "buttons/sort.html" with col='ports' text='Ports' %}{% include "buttons/sort.html" with col='stack' text='Stack' %}Id interne stack Détails
{% include "buttons/sort.html" with col="user" text="Utilisateur" %}{% include "buttons/sort.html" with col="reason" text="Raison" %}Raison {% include "buttons/sort.html" with col="start" text="Date de début" %} {% include "buttons/sort.html" with col="end" text="Date de fin" %}
{% include "buttons/sort.html" with col="user" text="Utilisateur" %}{% include "buttons/sort.html" with col="reason" text="Raison" %}Raison {% include "buttons/sort.html" with col="start" text="Date de début" %} {% include "buttons/sort.html" with col="end" text="Date de fin" %}
- + - - + + diff --git a/cotisations/templates/cotisations/control.html b/cotisations/templates/cotisations/control.html index 3282e29e..461494dd 100644 --- a/cotisations/templates/cotisations/control.html +++ b/cotisations/templates/cotisations/control.html @@ -40,14 +40,14 @@ with this program; if not, write to the Free Software Foundation, Inc., - - + + - - - - + + + + {% for form in controlform.forms %} diff --git a/logs/templates/logs/aff_stats_logs.html b/logs/templates/logs/aff_stats_logs.html index b0fa2b14..71efb147 100644 --- a/logs/templates/logs/aff_stats_logs.html +++ b/logs/templates/logs/aff_stats_logs.html @@ -33,8 +33,8 @@ with this program; if not, write to the Free Software Foundation, Inc., - - + + diff --git a/logs/templates/logs/aff_summary.html b/logs/templates/logs/aff_summary.html index a00c4e27..4fb5c8b1 100644 --- a/logs/templates/logs/aff_summary.html +++ b/logs/templates/logs/aff_summary.html @@ -31,7 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% include "buttons/sort.html" with col='user' text='Utilisateur' %}{% include "buttons/sort.html" with prefix='cotis' col='user' text='Utilisateur' %} Designation Prix total{% include "buttons/sort.html" with col='paiement' text='Moyen de paiement' %}{% include "buttons/sort.html" with col='date' text='Date' %}{% include "buttons/sort.html" with prefix='cotis' col='paiement' text='Moyen de paiement' %}{% include "buttons/sort.html" with prefix='cotis' col='date' text='Date' %}
Profil{% include "buttons/sort.html" with col='name' text='Nom' %}{% include "buttons/sort.html" with col='surname' text='Prénom' %}{% include "buttons/sort.html" with prefix='control' col='name' text='Nom' %}{% include "buttons/sort.html" with prefix='control' col='surname' text='Prénom' %} Designation Prix total{% include "buttons/sort.html" with col='paiement' text='Moyen de paiement' %}{% include "buttons/sort.html" with col='date' text='Date' %}{% include "buttons/sort.html" with col='valid' text='Valide' %}{% include "buttons/sort.html" with col='control' text='Contrôlée' %}{% include "buttons/sort.html" with prefix='control' col='paiement' text='Moyen de paiement' %}{% include "buttons/sort.html" with prefix='control' col='date' text='Date' %}{% include "buttons/sort.html" with prefix='control' col='valid' text='Valide' %}{% include "buttons/sort.html" with prefix='control' col='control' text='Contrôlée' %}
Objet modifié Type de l'objet{% include "buttons/sort.html" with col='author' text='Modification par' %}{% include "buttons/sort.html" with col='date' text='Date de modification' %}{% include "buttons/sort.html" with prefix='logs' col='author' text='Modification par' %}{% include "buttons/sort.html" with prefix='logs' col='date' text='Date de modification' %} Commentaire
- + diff --git a/machines/templates/machines/aff_machines.html b/machines/templates/machines/aff_machines.html index 93720997..b59bdc23 100644 --- a/machines/templates/machines/aff_machines.html +++ b/machines/templates/machines/aff_machines.html @@ -35,7 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc., - + diff --git a/re2o/utils.py b/re2o/utils.py index 5c95c47a..7ec29e87 100644 --- a/re2o/utils.py +++ b/re2o/utils.py @@ -153,76 +153,76 @@ class SortTable: # A 'default' might be provided to specify what to do if the requested col # doesn't match any keys. USERS_INDEX = { - 'name': ['name'], - 'surname': ['surname'], - 'pseudo': ['pseudo'], - 'room': ['room'], + 'user_name': ['name'], + 'user_surname': ['surname'], + 'user_pseudo': ['pseudo'], + 'user_room': ['room'], 'default': ['state', 'pseudo'] } USERS_INDEX_BAN = { - 'user': ['user__pseudo'], - 'start': ['date_start'], - 'end': ['date_end'], + 'ban_user': ['user__pseudo'], + 'ban_start': ['date_start'], + 'ban_end': ['date_end'], 'default': ['-date_end'] } USERS_INDEX_WHITE = { - 'user': ['user__pseudo'], - 'start': ['date_start'], - 'end': ['date_end'], + 'white_user': ['user__pseudo'], + 'white_start': ['date_start'], + 'white_end': ['date_end'], 'default': ['-date_end'] } MACHINES_INDEX = { - 'name': ['name'], + 'machine_name': ['name'], 'default': ['pk'] } COTISATIONS_INDEX = { - 'user': ['user__pseudo'], - 'paiement': ['paiement__moyen'], - 'date': ['date'], + 'cotis_user': ['user__pseudo'], + 'cotis_paiement': ['paiement__moyen'], + 'cotis_date': ['date'], 'default': ['-date'] } COTISATIONS_CONTROL = { - 'name': ['user__name'], - 'surname': ['user__surname'], - 'paiement': ['paiement'], - 'date': ['date'], - 'valid': ['valid'], - 'control': ['control'], + 'control_name': ['user__name'], + 'control_surname': ['user__surname'], + 'control_paiement': ['paiement'], + 'control_date': ['date'], + 'control_valid': ['valid'], + 'control_control': ['control'], 'default': ['-date'] } TOPOLOGIE_INDEX = { - 'dns': ['switch_interface__domain__name'], - 'ip': ['switch_interface__ipv4__ipv4'], - 'loc': ['location'], - 'ports': ['number'], - 'stack': ['stack__name'], + 'switch_dns': ['switch_interface__domain__name'], + 'switch_ip': ['switch_interface__ipv4__ipv4'], + 'switch_loc': ['location'], + 'switch_ports': ['number'], + 'switch_stack': ['stack__name'], 'default': ['location', 'stack', 'stack_member_id'] } TOPOLOGIE_INDEX_PORT = { - 'port': ['port'], - 'room': ['room__name'], - 'interface': ['machine_interface__domain__name'], - 'related': ['related__switch__name'], - 'radius': ['radius'], - 'vlan': ['vlan_force__name'], + 'port_port': ['port'], + 'port_room': ['room__name'], + 'port_interface': ['machine_interface__domain__name'], + 'port_related': ['related__switch__name'], + 'port_radius': ['radius'], + 'port_vlan': ['vlan_force__name'], 'default': ['port'] } TOPOLOGIE_INDEX_ROOM = { - 'name': ['name'], + 'room_name': ['name'], 'default': ['name'] } TOPOLOGIE_INDEX_STACK = { - 'name': ['name'], - 'id': ['stack_id'], + 'stack_name': ['name'], + 'stack_id': ['stack_id'], 'default': ['stack_id'], } LOGS_INDEX = { - 'date': ['revision__date_created'], + 'sum_date': ['revision__date_created'], 'default': ['-revision__date_created'], } LOGS_STATS_LOGS = { - 'author': ['user__name'], - 'date': ['date_created'], + 'logs_author': ['user__name'], + 'logs_date': ['date_created'], 'default': ['-date_created'] } diff --git a/templates/buttons/sort.html b/templates/buttons/sort.html index 7fe59784..e90fbd15 100644 --- a/templates/buttons/sort.html +++ b/templates/buttons/sort.html @@ -28,12 +28,23 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{{ text }} 
+ {% if prefix %} + {% with prefix|add:'_'|add:col as colname %} + + + + + + + {% endwith %} + {% else %} + {% endif %}
{% endspaceless %} diff --git a/topologie/templates/topologie/aff_chambres.html b/topologie/templates/topologie/aff_chambres.html index 8ac3e5d8..252ff808 100644 --- a/topologie/templates/topologie/aff_chambres.html +++ b/topologie/templates/topologie/aff_chambres.html @@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% include "buttons/sort.html" with col='date' text='Date' %}{% include "buttons/sort.html" with prefix='sum' col='date' text='Date' %} Modification
{% include "buttons/sort.html" with col='name' text='Nom DNS' %}{% include "buttons/sort.html" with prefix='machine' col='name' text='Nom DNS' %} Type MAC IP
- + diff --git a/topologie/templates/topologie/aff_port.html b/topologie/templates/topologie/aff_port.html index 16b4f258..6d1ca08e 100644 --- a/topologie/templates/topologie/aff_port.html +++ b/topologie/templates/topologie/aff_port.html @@ -25,12 +25,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% include "buttons/sort.html" with col='name' text='Chambre' %}{% include "buttons/sort.html" with prefix='room' col='name' text='Chambre' %} Commentaire
- - - - - - + + + + + + diff --git a/topologie/templates/topologie/aff_stacks.html b/topologie/templates/topologie/aff_stacks.html index b3ac49ba..1a9d316e 100644 --- a/topologie/templates/topologie/aff_stacks.html +++ b/topologie/templates/topologie/aff_stacks.html @@ -25,8 +25,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% include "buttons/sort.html" with col='port' text='Port' %}{% include "buttons/sort.html" with col='room' text='Room' %}{% include "buttons/sort.html" with col='interface' text='Interface machine' %}{% include "buttons/sort.html" with col='related' text='Related' %}{% include "buttons/sort.html" with col='radius' text='Radius' %}{% include "buttons/sort.html" with col='vlan' text='Vlan forcé' %}{% include "buttons/sort.html" with prefix='port' col='port' text='Port' %}{% include "buttons/sort.html" with prefix='port' col='room' text='Room' %}{% include "buttons/sort.html" with prefix='port' col='interface' text='Interface machine' %}{% include "buttons/sort.html" with prefix='port' col='related' text='Related' %}{% include "buttons/sort.html" with prefix='port' col='radius' text='Radius' %}{% include "buttons/sort.html" with prefix='port' col='vlan' text='Vlan forcé' %} Détails
- - + + diff --git a/topologie/templates/topologie/aff_switch.html b/topologie/templates/topologie/aff_switch.html index 894e89a4..f503798e 100644 --- a/topologie/templates/topologie/aff_switch.html +++ b/topologie/templates/topologie/aff_switch.html @@ -25,11 +25,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% include "buttons/sort.html" with col='name' text='Stack' %}{% include "buttons/sort.html" with col='id' text='ID' %}{% include "buttons/sort.html" with prefix='stack' col='name' text='Stack' %}{% include "buttons/sort.html" with prefix='stack' col='id' text='ID' %} Détails Membres
- - - - - + + + + + diff --git a/users/templates/users/aff_bans.html b/users/templates/users/aff_bans.html index 3b4b66c1..78834123 100644 --- a/users/templates/users/aff_bans.html +++ b/users/templates/users/aff_bans.html @@ -29,10 +29,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% include "buttons/sort.html" with col='dns' text='Dns' %}{% include "buttons/sort.html" with col='ip' text='Ipv4' %}{% include "buttons/sort.html" with col='loc' text='Localisation' %}{% include "buttons/sort.html" with col='ports' text='Ports' %}{% include "buttons/sort.html" with col='stack' text='Stack' %}{% include "buttons/sort.html" with prefix='switch' col='dns' text='Dns' %}{% include "buttons/sort.html" with prefix='switch' col='ip' text='Ipv4' %}{% include "buttons/sort.html" with prefix='switch' col='loc' text='Localisation' %}{% include "buttons/sort.html" with prefix='switch' col='ports' text='Ports' %}{% include "buttons/sort.html" with prefix='switch' col='stack' text='Stack' %} Id interne stack Détails
- + - - + + diff --git a/users/templates/users/aff_users.html b/users/templates/users/aff_users.html index ad39ea38..c03cfa74 100644 --- a/users/templates/users/aff_users.html +++ b/users/templates/users/aff_users.html @@ -29,10 +29,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% include "buttons/sort.html" with col="user" text="Utilisateur" %}{% include "buttons/sort.html" with prefix='ban' col="user" text="Utilisateur" %} Raison{% include "buttons/sort.html" with col="start" text="Date de début" %}{% include "buttons/sort.html" with col="end" text="Date de fin" %}{% include "buttons/sort.html" with prefix='ban' col="start" text="Date de début" %}{% include "buttons/sort.html" with prefix='ban' col="end" text="Date de fin" %}
- - - - + + + + diff --git a/users/templates/users/aff_whitelists.html b/users/templates/users/aff_whitelists.html index 28b8537f..07d434c0 100644 --- a/users/templates/users/aff_whitelists.html +++ b/users/templates/users/aff_whitelists.html @@ -29,10 +29,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% include "buttons/sort.html" with col="name" text="Prénom" %}{% include "buttons/sort.html" with col="surname" text="Nom" %}{% include "buttons/sort.html" with col="pseudo" text="Pseudo" %}{% include "buttons/sort.html" with col="room" text="Chambre" %}{% include "buttons/sort.html" with prefix='user' col="name" text="Prénom" %}{% include "buttons/sort.html" with prefix='user' col="surname" text="Nom" %}{% include "buttons/sort.html" with prefix='user' col="pseudo" text="Pseudo" %}{% include "buttons/sort.html" with prefix='user' col="room" text="Chambre" %} Fin de cotisation le Connexion Profil
- + - - + + From d1ee75bb1751f7d971ba1c0276ff2eecef6a440c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sun, 22 Oct 2017 16:04:51 +0000 Subject: [PATCH 9/9] Ajoute le tri des cotis/ban/whitelist/machines sur la page d'un user --- users/views.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/users/views.py b/users/views.py index 316c85ea..d8d4be62 100644 --- a/users/views.py +++ b/users/views.py @@ -792,9 +792,33 @@ def profil(request, userid): .prefetch_related('interface_set__ipv4__ip_type__extension')\ .prefetch_related('interface_set__type')\ .prefetch_related('interface_set__domain__related_domain__extension') + machines = SortTable.sort( + machines, + request.GET.get('col'), + request.GET.get('order'), + SortTable.MACHINES_INDEX + ) factures = Facture.objects.filter(user=users) + factures = SortTable.sort( + factures, + request.GET.get('col'), + request.GET.get('order'), + SortTable.COTISATIONS_INDEX + ) bans = Ban.objects.filter(user=users) + bans = SortTable.sort( + bans, + request.GET.get('col'), + request.GET.get('order'), + SortTable.USERS_INDEX_BAN + ) whitelists = Whitelist.objects.filter(user=users) + whitelists = SortTable.sort( + whitelists, + request.GET.get('col'), + request.GET.get('order'), + SortTable.USERS_INDEX_WHITE + ) list_droits = Right.objects.filter(user=users) options, _created = OptionalUser.objects.get_or_create() user_solde = options.user_solde
{% include "buttons/sort.html" with col="user" text="Utilisateur" %}{% include "buttons/sort.html" with prefix='white' col="user" text="Utilisateur" %} Raison{% include "buttons/sort.html" with col="start" text="Date de début" %}{% include "buttons/sort.html" with col="end" text="Date de fin" %}{% include "buttons/sort.html" with prefix='white' col="start" text="Date de début" %}{% include "buttons/sort.html" with prefix='white' col="end" text="Date de fin" %}