8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-26 00:43:46 +00:00

Merge branch 'sort_columns' into 'master'

Sort columns

See merge request rezo/re2o!24
This commit is contained in:
Maël Kervella 2017-10-22 18:49:27 +02:00
commit a6c29c6f42
21 changed files with 412 additions and 75 deletions

View file

@ -29,11 +29,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
<th>Utilisateur</th> <th>{% include "buttons/sort.html" with prefix='cotis' col='user' text='Utilisateur' %}</th>
<th>Designation</th> <th>Designation</th>
<th>Prix total</th> <th>Prix total</th>
<th>Moyen de paiement</th> <th>{% include "buttons/sort.html" with prefix='cotis' col='paiement' text='Moyen de paiement' %}</th>
<th>Date</th> <th>{% include "buttons/sort.html" with prefix='cotis' col='date' text='Date' %}</th>
<th></th> <th></th>
<th></th> <th></th>
<th></th> <th></th>

View file

@ -40,14 +40,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<thead> <thead>
<tr> <tr>
<th>Profil</th> <th>Profil</th>
<th>Nom</th> <th>{% include "buttons/sort.html" with prefix='control' col='name' text='Nom' %}</th>
<th>Prénom</th> <th>{% include "buttons/sort.html" with prefix='control' col='surname' text='Prénom' %}</th>
<th>Designation</th> <th>Designation</th>
<th>Prix total</th> <th>Prix total</th>
<th>Moyen de paiement</th> <th>{% include "buttons/sort.html" with prefix='control' col='paiement' text='Moyen de paiement' %}</th>
<th>Date</th> <th>{% include "buttons/sort.html" with prefix='control' col='date' text='Date' %}</th>
<th>Validité</th> <th>{% include "buttons/sort.html" with prefix='control' col='valid' text='Valide' %}</th>
<th>Controle trésorier</th> <th>{% include "buttons/sort.html" with prefix='control' col='control' text='Contrôlée' %}</th>
</tr> </tr>
</thead> </thead>
{% for form in controlform.forms %} {% for form in controlform.forms %}

View file

@ -40,6 +40,7 @@ from users.models import User
from re2o.settings import LOGO_PATH from re2o.settings import LOGO_PATH
from re2o import settings from re2o import settings
from re2o.views import form from re2o.views import form
from re2o.utils import SortTable
from preferences.models import OptionalUser, AssoOption, GeneralOption from preferences.models import OptionalUser, AssoOption, GeneralOption
from .models import Facture, Article, Vente, Paiement, Banque from .models import Facture, Article, Vente, Paiement, Banque
from .forms import NewFactureForm, TrezEditFactureForm, EditFactureForm from .forms import NewFactureForm, TrezEditFactureForm, EditFactureForm
@ -519,7 +520,13 @@ def control(request):
factures.Case à cocher, pratique""" factures.Case à cocher, pratique"""
options, _created = GeneralOption.objects.get_or_create() options, _created = GeneralOption.objects.get_or_create()
pagination_number = options.pagination_number 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( controlform_set = modelformset_factory(
Facture, Facture,
fields=('control', 'valid'), fields=('control', 'valid'),
@ -533,11 +540,7 @@ def control(request):
facture_list = paginator.page(1) facture_list = paginator.page(1)
except EmptyPage: except EmptyPage:
facture_list = paginator.page(paginator.num.pages) facture_list = paginator.page(paginator.num.pages)
page_query = Facture.objects.order_by('date').select_related('user')\ controlform = controlform_set(request.POST or None, queryset=facture_list.object_list)
.select_related('paiement').reverse().filter(
id__in=[facture.id for facture in facture_list]
)
controlform = controlform_set(request.POST or None, queryset=page_query)
if controlform.is_valid(): if controlform.is_valid():
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
controlform.save() controlform.save()
@ -586,8 +589,14 @@ def index(request):
"""Affiche l'ensemble des factures, pour les cableurs et +""" """Affiche l'ensemble des factures, pour les cableurs et +"""
options, _created = GeneralOption.objects.get_or_create() options, _created = GeneralOption.objects.get_or_create()
pagination_number = options.pagination_number pagination_number = options.pagination_number
facture_list = Facture.objects.order_by('date').select_related('user')\ facture_list = Facture.objects.select_related('user')\
.select_related('paiement').prefetch_related('vente_set').reverse() .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) paginator = Paginator(facture_list, pagination_number)
page = request.GET.get('page') page = request.GET.get('page')
try: try:

View file

@ -33,8 +33,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<tr> <tr>
<th>Objet modifié</th> <th>Objet modifié</th>
<th>Type de l'objet</th> <th>Type de l'objet</th>
<th>Modification par</th> <th>{% include "buttons/sort.html" with prefix='logs' col='author' text='Modification par' %}</th>
<th>Date de modification</th> <th>{% include "buttons/sort.html" with prefix='logs' col='date' text='Date de modification' %}</th>
<th>Commentaire</th> <th>Commentaire</th>
<th></th> <th></th>
</tr> </tr>

View file

@ -31,7 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
<th>Date</th> <th>{% include "buttons/sort.html" with prefix='sum' col='date' text='Date' %}</th>
<th>Modification</th> <th>Modification</th>
<th></th> <th></th>
</tr> </tr>

View file

@ -57,7 +57,7 @@ from preferences.models import GeneralOption
from re2o.views import form from re2o.views import form
from re2o.utils import all_whitelisted, all_baned, all_has_access, all_adherent 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_assigned_interfaces_count
from re2o.utils import all_active_interfaces_count from re2o.utils import all_active_interfaces_count, SortTable
STATS_DICT = { STATS_DICT = {
0: ["Tout", 36], 0: ["Tout", 36],
@ -83,7 +83,13 @@ def index(request):
content_type__in=ContentType.objects.filter( content_type__in=ContentType.objects.filter(
model__in=content_type_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) paginator = Paginator(versions, pagination_number)
page = request.GET.get('page') page = request.GET.get('page')
try: try:
@ -129,9 +135,14 @@ def stats_logs(request):
classés par date croissante, en vrac""" classés par date croissante, en vrac"""
options, _created = GeneralOption.objects.get_or_create() options, _created = GeneralOption.objects.get_or_create()
pagination_number = options.pagination_number pagination_number = options.pagination_number
revisions = Revision.objects.all().order_by('date_created')\ revisions = Revision.objects.all().select_related('user')\
.reverse().select_related('user')\
.prefetch_related('version_set__object') .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) paginator = Paginator(revisions, pagination_number)
page = request.GET.get('page') page = request.GET.get('page')
try: try:

View file

@ -35,7 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<col width="144px"> <col width="144px">
</colgroup> </colgroup>
<thead> <thead>
<th>Nom DNS</th> <th>{% include "buttons/sort.html" with prefix='machine' col='name' text='Nom DNS' %}</th>
<th>Type</th> <th>Type</th>
<th>MAC</th> <th>MAC</th>
<th>IP</th> <th>IP</th>
@ -44,7 +44,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% for machine in machines_list %} {% for machine in machines_list %}
<tr class="info"> <tr class="info">
<td colspan="4"> <td colspan="4">
<b>{{ machine.name }}</b> <i class="glyphicon glyphicon-chevron-right"></i> <b>{{ machine.name|default:'<i>Pas de nom</i>' }}</b> <i class="glyphicon glyphicon-chevron-right"></i>
<a href="{% url 'users:profil' userid=machine.user.id %}" title="Voir le profil"> <a href="{% url 'users:profil' userid=machine.user.id %}" title="Voir le profil">
<i class="glyphicon glyphicon-user"></i> {{ machine.user }} <i class="glyphicon glyphicon-user"></i> {{ machine.user }}
</a> </a>

View file

@ -117,7 +117,8 @@ from preferences.models import GeneralOption, OptionalMachine
from re2o.utils import ( from re2o.utils import (
all_active_assigned_interfaces, all_active_assigned_interfaces,
all_has_access, all_has_access,
filter_active_interfaces filter_active_interfaces,
SortTable
) )
from re2o.views import form from re2o.views import form
@ -936,7 +937,13 @@ def del_nas(request):
def index(request): def index(request):
options, created = GeneralOption.objects.get_or_create() options, created = GeneralOption.objects.get_or_create()
pagination_large_number = options.pagination_large_number 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) paginator = Paginator(machines_list, pagination_large_number)
page = request.GET.get('page') page = request.GET.get('page')
try: try:

View file

@ -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 ?<existing_param>&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]

View file

@ -139,3 +139,102 @@ def all_active_interfaces_count():
def all_active_assigned_interfaces_count(): def all_active_assigned_interfaces_count():
""" Version light seulement pour compter""" """ Version light seulement pour compter"""
return all_active_interfaces_count().filter(ipv4__isnull=False) 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 possible values
# The naming convention is based on the URL or the views function
# 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 = {
'user_name': ['name'],
'user_surname': ['surname'],
'user_pseudo': ['pseudo'],
'user_room': ['room'],
'default': ['state', 'pseudo']
}
USERS_INDEX_BAN = {
'ban_user': ['user__pseudo'],
'ban_start': ['date_start'],
'ban_end': ['date_end'],
'default': ['-date_end']
}
USERS_INDEX_WHITE = {
'white_user': ['user__pseudo'],
'white_start': ['date_start'],
'white_end': ['date_end'],
'default': ['-date_end']
}
MACHINES_INDEX = {
'machine_name': ['name'],
'default': ['pk']
}
COTISATIONS_INDEX = {
'cotis_user': ['user__pseudo'],
'cotis_paiement': ['paiement__moyen'],
'cotis_date': ['date'],
'default': ['-date']
}
COTISATIONS_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 = {
'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': ['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 = {
'room_name': ['name'],
'default': ['name']
}
TOPOLOGIE_INDEX_STACK = {
'stack_name': ['name'],
'stack_id': ['stack_id'],
'default': ['stack_id'],
}
LOGS_INDEX = {
'sum_date': ['revision__date_created'],
'default': ['-revision__date_created'],
}
LOGS_STATS_LOGS = {
'logs_author': ['user__name'],
'logs_date': ['date_created'],
'default': ['-date_created']
}
@staticmethod
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 """
fields = values.get(col, None)
if not fields:
fields = values.get('default', [])
request = request.order_by(*fields)
if order == 'desc':
return request.reverse()
else:
return request

View file

@ -0,0 +1,50 @@
{% 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 %}
{% load url_insert_param %}
{% spaceless %}
<div style="display: flex; padding: 0;">
{{ text }}&nbsp;
<div style="display: grid; font-size: 9px; line-height: 1; margin: auto 0;">
{% if prefix %}
{% with prefix|add:'_'|add:col as colname %}
<a role="button" href="{% url_insert_param request.get_full_path col=colname order='asc' %}" title="{{ desc|default:"Tri croissant" }}">
<span class="glyphicon glyphicon-triangle-top"></span>
</a>
<a role="button" href="{% url_insert_param request.get_full_path col=colname order='desc' %}" title="{{ desc|default:"Tri décroissant" }}">
<span class="glyphicon glyphicon-triangle-bottom"></span>
</a>
{% endwith %}
{% else %}
<a role="button" href="{% url_insert_param request.get_full_path col=col order='asc' %}" title="{{ desc|default:"Tri croissant" }}">
<span class="glyphicon glyphicon-triangle-top"></span>
</a>
<a role="button" href="{% url_insert_param request.get_full_path col=col order='desc' %}" title="{{ desc|default:"Tri décroissant" }}">
<span class="glyphicon glyphicon-triangle-bottom"></span>
</a>
{% endif %}
</div>
</div>
{% endspaceless %}

View file

@ -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. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %} {% endcomment %}
{% load url_insert_param %}
<ul class="pagination nav navbar-nav"> <ul class="pagination nav navbar-nav">
{% if list.has_previous %} {% if list.has_previous %}
<li><a href="?page=1"> << </a></li> <li><a href="{% url_insert_param request.get_full_path page=1 %}"> << </a></li>
<li><a href="?page={{ list.previous_page_number }}"> < </a></li> <li><a href="{% url_insert_param request.get_full_path page=list.previous_page_number %}"> < </a></li>
{% endif %} {% endif %}
{% for page in list.paginator.page_range %} {% for page in list.paginator.page_range %}
{% if list.number <= page|add:"3" and list.number >= page|add:"-3" %} {% if list.number <= page|add:"3" and list.number >= page|add:"-3" %}
<li class="{% if list.number == page %}active{% endif %}"><a href="?page={{page }}">{{ page }}</a></li> <li class="{% if list.number == page %}active{% endif %}"><a href="{% url_insert_param request.get_full_path page=page %}">{{ page }}</a></li>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% if list.has_next %} {% if list.has_next %}
<li><a href="?page={{ list.next_page_number }}"> > </a></li> <li><a href="{% url_insert_param request.get_full_path page=list.next_page_number %}"> > </a></li>
<li><a href="?page={{ list.paginator.page_range|length }}"> >> </a></li> <li><a href="{% url_insert_param request.get_full_path page=list.paginator.page_range|length %}"> >> </a></li>
{% endif %} {% endif %}
</ul> </ul>

View file

@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
<th>Chambre</th> <th>{% include "buttons/sort.html" with prefix='room' col='name' text='Chambre' %}</th>
<th>Commentaire</th> <th>Commentaire</th>
<th></th> <th></th>
</tr> </tr>

View file

@ -25,12 +25,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
<th>Port</th> <th>{% include "buttons/sort.html" with prefix='port' col='port' text='Port' %}</th>
<th>Room</th> <th>{% include "buttons/sort.html" with prefix='port' col='room' text='Room' %}</th>
<th>Interface machine</th> <th>{% include "buttons/sort.html" with prefix='port' col='interface' text='Interface machine' %}</th>
<th>Related</th> <th>{% include "buttons/sort.html" with prefix='port' col='related' text='Related' %}</th>
<th>Radius</th> <th>{% include "buttons/sort.html" with prefix='port' col='radius' text='Radius' %}</th>
<th>Vlan forcé</th> <th>{% include "buttons/sort.html" with prefix='port' col='vlan' text='Vlan forcé' %}</th>
<th>Détails</th> <th>Détails</th>
<th></th> <th></th>
</tr> </tr>

View file

@ -25,9 +25,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
<th>Stack</th> <th>{% include "buttons/sort.html" with prefix='stack' col='name' text='Stack' %}</th>
<th>ID</th> <th>{% include "buttons/sort.html" with prefix='stack' col='id' text='ID' %}</th>
<th>Details</th> <th>Détails</th>
<th>Membres</th> <th>Membres</th>
</tr> </tr>
</thead> </thead>

View file

@ -25,12 +25,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
<th>Dns</th> <th>{% include "buttons/sort.html" with prefix='switch' col='dns' text='Dns' %}</th>
<th>Ipv4</th> <th>{% include "buttons/sort.html" with prefix='switch' col='ip' text='Ipv4' %}</th>
<th>Localisation</th> <th>{% include "buttons/sort.html" with prefix='switch' col='loc' text='Localisation' %}</th>
<th>Ports</th> <th>{% include "buttons/sort.html" with prefix='switch' col='ports' text='Ports' %}</th>
<th>Stack</th> <th>{% include "buttons/sort.html" with prefix='switch' col='stack' text='Stack' %}</th>
<th>id interne Stack</th> <th>Id interne stack</th>
<th>Détails</th> <th>Détails</th>
<th></th> <th></th>
</tr> </tr>

View file

@ -49,7 +49,7 @@ from topologie.models import Switch, Port, Room, Stack
from topologie.forms import EditPortForm, NewSwitchForm, EditSwitchForm from topologie.forms import EditPortForm, NewSwitchForm, EditSwitchForm
from topologie.forms import AddPortForm, EditRoomForm, StackForm from topologie.forms import AddPortForm, EditRoomForm, StackForm
from users.views import form from users.views import form
from re2o.utils import SortTable
from machines.forms import DomainForm, NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm from machines.forms import DomainForm, NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm
from machines.views import generate_ipv4_mbf_param from machines.views import generate_ipv4_mbf_param
from preferences.models import AssoOption, GeneralOption from preferences.models import AssoOption, GeneralOption
@ -59,15 +59,17 @@ from preferences.models import AssoOption, GeneralOption
@permission_required('cableur') @permission_required('cableur')
def index(request): def index(request):
""" Vue d'affichage de tous les swicthes""" """ Vue d'affichage de tous les swicthes"""
switch_list = Switch.objects.order_by( switch_list = Switch.objects\
'stack',
'stack_member_id',
'location'
)\
.select_related('switch_interface__domain__extension')\ .select_related('switch_interface__domain__extension')\
.select_related('switch_interface__ipv4')\ .select_related('switch_interface__ipv4')\
.select_related('switch_interface__domain')\ .select_related('switch_interface__domain')\
.select_related('stack') .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', { return render(request, 'topologie/index.html', {
'switch_list': switch_list 'switch_list': switch_list
}) })
@ -137,8 +139,13 @@ def index_port(request, switch_id):
.select_related('machine_interface__domain__extension')\ .select_related('machine_interface__domain__extension')\
.select_related('machine_interface__machine__user')\ .select_related('machine_interface__machine__user')\
.select_related('related__switch__switch_interface__domain__extension')\ .select_related('related__switch__switch_interface__domain__extension')\
.select_related('switch')\ .select_related('switch')
.order_by('port') 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', { return render(request, 'topologie/index_p.html', {
'port_list': port_list, 'port_list': port_list,
'id_switch': switch_id, 'id_switch': switch_id,
@ -150,7 +157,13 @@ def index_port(request, switch_id):
@permission_required('cableur') @permission_required('cableur')
def index_room(request): def index_room(request):
""" Affichage de l'ensemble des chambres""" """ 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'),
request.GET.get('order'),
SortTable.TOPOLOGIE_INDEX_ROOM
)
options, _created = GeneralOption.objects.get_or_create() options, _created = GeneralOption.objects.get_or_create()
pagination_number = options.pagination_number pagination_number = options.pagination_number
paginator = Paginator(room_list, pagination_number) paginator = Paginator(room_list, pagination_number)
@ -172,8 +185,14 @@ def index_room(request):
@permission_required('infra') @permission_required('infra')
def index_stack(request): def index_stack(request):
"""Affichage de la liste des stacks (affiche l'ensemble des switches)""" """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') .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', { return render(request, 'topologie/index_stack.html', {
'stack_list': stack_list 'stack_list': stack_list
}) })

View file

@ -29,10 +29,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
<th>Utilisateur</th> <th>{% include "buttons/sort.html" with prefix='ban' col="user" text="Utilisateur" %}</th>
<th>Raison</th> <th>Raison</th>
<th>Date de début</th> <th>{% include "buttons/sort.html" with prefix='ban' col="start" text="Date de début" %}</th>
<th>Date de fin</th> <th>{% include "buttons/sort.html" with prefix='ban' col="end" text="Date de fin" %}</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>

View file

@ -29,10 +29,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
<th>Prénom</th> <th>{% include "buttons/sort.html" with prefix='user' col="name" text="Prénom" %}</th>
<th>Nom</th> <th>{% include "buttons/sort.html" with prefix='user' col="surname" text="Nom" %}</th>
<th>Pseudo</th> <th>{% include "buttons/sort.html" with prefix='user' col="pseudo" text="Pseudo" %}</th>
<th>Chambre</th> <th>{% include "buttons/sort.html" with prefix='user' col="room" text="Chambre" %}</th>
<th>Fin de cotisation le</th> <th>Fin de cotisation le</th>
<th>Connexion</th> <th>Connexion</th>
<th>Profil</th> <th>Profil</th>

View file

@ -29,10 +29,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
<th>Utilisateur</th> <th>{% include "buttons/sort.html" with prefix='white' col="user" text="Utilisateur" %}</th>
<th>Raison</th> <th>Raison</th>
<th>Date de début</th> <th>{% include "buttons/sort.html" with prefix='white' col="start" text="Date de début" %}</th>
<th>Date de fin</th> <th>{% include "buttons/sort.html" with prefix='white' col="end" text="Date de fin" %}</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>

View file

@ -65,7 +65,7 @@ from machines.models import Machine
from preferences.models import OptionalUser, GeneralOption from preferences.models import OptionalUser, GeneralOption
from re2o.views import form 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): def password_change_action(u_form, user, request, req=False):
""" Fonction qui effectue le changeemnt de mdp bdd""" """ Fonction qui effectue le changeemnt de mdp bdd"""
@ -575,7 +575,13 @@ def index(request):
""" Affiche l'ensemble des users, need droit cableur """ """ Affiche l'ensemble des users, need droit cableur """
options, _created = GeneralOption.objects.get_or_create() options, _created = GeneralOption.objects.get_or_create()
pagination_number = options.pagination_number 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'),
request.GET.get('order'),
SortTable.USERS_INDEX
)
paginator = Paginator(users_list, pagination_number) paginator = Paginator(users_list, pagination_number)
page = request.GET.get('page') page = request.GET.get('page')
try: try:
@ -595,8 +601,13 @@ def index_ban(request):
""" Affiche l'ensemble des ban, need droit cableur """ """ Affiche l'ensemble des ban, need droit cableur """
options, _created = GeneralOption.objects.get_or_create() options, _created = GeneralOption.objects.get_or_create()
pagination_number = options.pagination_number pagination_number = options.pagination_number
ban_list = Ban.objects.order_by('date_start')\ ban_list = Ban.objects.select_related('user')
.select_related('user').reverse() ban_list = SortTable.sort(
ban_list,
request.GET.get('col'),
request.GET.get('order'),
SortTable.USERS_INDEX_BAN
)
paginator = Paginator(ban_list, pagination_number) paginator = Paginator(ban_list, pagination_number)
page = request.GET.get('page') page = request.GET.get('page')
try: try:
@ -616,8 +627,13 @@ def index_white(request):
""" Affiche l'ensemble des whitelist, need droit cableur """ """ Affiche l'ensemble des whitelist, need droit cableur """
options, _created = GeneralOption.objects.get_or_create() options, _created = GeneralOption.objects.get_or_create()
pagination_number = options.pagination_number pagination_number = options.pagination_number
white_list = Whitelist.objects.select_related('user')\ white_list = Whitelist.objects.select_related('user')
.order_by('date_start') white_list = SortTable.sort(
white_list,
request.GET.get('col'),
request.GET.get('order'),
SortTable.USERS_INDEX_BAN
)
paginator = Paginator(white_list, pagination_number) paginator = Paginator(white_list, pagination_number)
page = request.GET.get('page') page = request.GET.get('page')
try: try:
@ -776,9 +792,33 @@ def profil(request, userid):
.prefetch_related('interface_set__ipv4__ip_type__extension')\ .prefetch_related('interface_set__ipv4__ip_type__extension')\
.prefetch_related('interface_set__type')\ .prefetch_related('interface_set__type')\
.prefetch_related('interface_set__domain__related_domain__extension') .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 = 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 = 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 = 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) list_droits = Right.objects.filter(user=users)
options, _created = OptionalUser.objects.get_or_create() options, _created = OptionalUser.objects.get_or_create()
user_solde = options.user_solde user_solde = options.user_solde