Commit 3cc2c593 authored by Maël Kervella's avatar Maël Kervella

Ajout du sort dans topo, logs, machines, cotisations

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 ?
parent 46e1b784
......@@ -29,11 +29,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<table class="table table-striped">
<thead>
<tr>
<th>Utilisateur</th>
<th>{% include "buttons/sort.html" with col='user' text='Utilisateur' %}</th>
<th>Designation</th>
<th>Prix total</th>
<th>Moyen de paiement</th>
<th>Date</th>
<th>{% include "buttons/sort.html" with col='paiement' text='Moyen de paiement' %}</th>
<th>{% include "buttons/sort.html" with col='date' text='Date' %}</th>
<th></th>
<th></th>
<th></th>
......
......@@ -40,14 +40,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<thead>
<tr>
<th>Profil</th>
<th>Nom</th>
<th>Prénom</th>
<th>{% include "buttons/sort.html" with col='name' text='Nom' %}</th>
<th>{% include "buttons/sort.html" with col='surname' text='Prénom' %}</th>
<th>Designation</th>
<th>Prix total</th>
<th>Moyen de paiement</th>
<th>Date</th>
<th>Validité</th>
<th>Controle trésorier</th>
<th>{% include "buttons/sort.html" with col='paiement' text='Moyen de paiement' %}</th>
<th>{% include "buttons/sort.html" with col='date' text='Date' %}</th>
<th>{% include "buttons/sort.html" with col='valid' text='Valide' %}</th>
<th>{% include "buttons/sort.html" with col='control' text='Contrôlée' %}</th>
</tr>
</thead>
{% for form in controlform.forms %}
......
......@@ -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:
......
......@@ -33,8 +33,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<tr>
<th>Objet modifié</th>
<th>Type de l'objet</th>
<th>Modification par</th>
<th>Date de modification</th>
<th>{% include "buttons/sort.html" with col='author' text='Modification par' %}</th>
<th>{% include "buttons/sort.html" with col='date' text='Date de modification' %}</th>
<th>Commentaire</th>
<th></th>
</tr>
......
......@@ -31,7 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<table class="table table-striped">
<thead>
<tr>
<th>Date</th>
<th>{% include "buttons/sort.html" with col='date' text='Date' %}</th>
<th>Modification</th>
<th></th>
</tr>
......
......@@ -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:
......
......@@ -35,7 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<col width="144px">
</colgroup>
<thead>
<th>Nom DNS</th>
<th>{% include "buttons/sort.html" with col='name' text='Nom DNS' %}</th>
<th>Type</th>
<th>MAC</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 %}
<tr class="info">
<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">
<i class="glyphicon glyphicon-user"></i> {{ machine.user }}
</a>
......
......@@ -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:
......
......@@ -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):
......
......@@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<table class="table table-striped">
<thead>
<tr>
<th>Chambre</th>
<th>{% include "buttons/sort.html" with col='name' text='Chambre' %}</th>
<th>Commentaire</th>
<th></th>
</tr>
......
......@@ -25,12 +25,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<table class="table table-striped">
<thead>
<tr>
<th>Port</th>
<th>Room</th>
<th>Interface machine</th>
<th>Related</th>
<th>Radius</th>
<th>Vlan forcé</th>
<th>{% include "buttons/sort.html" with col='port' text='Port' %}</th>
<th>{% include "buttons/sort.html" with col='room' text='Room' %}</th>
<th>{% include "buttons/sort.html" with col='interface' text='Interface machine' %}</th>
<th>{% include "buttons/sort.html" with col='related' text='Related' %}</th>
<th>{% include "buttons/sort.html" with col='radius' text='Radius' %}</th>
<th>{% include "buttons/sort.html" with col='vlan' text='Vlan forcé' %}</th>
<th>Détails</th>
<th></th>
</tr>
......
......@@ -25,9 +25,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<table class="table table-striped">
<thead>
<tr>
<th>Stack</th>
<th>ID</th>
<th>Details</th>
<th>{% include "buttons/sort.html" with col='name' text='Stack' %}</th>
<th>{% include "buttons/sort.html" with col='id' text='ID' %}</th>
<th>Détails</th>
<th>Membres</th>
</tr>
</thead>
......
......@@ -25,12 +25,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<table class="table table-striped">
<thead>
<tr>
<th>Dns</th>
<th>Ipv4</th>
<th>Localisation</th>
<th>Ports</th>
<th>Stack</th>
<th>id interne Stack</th>
<th>{% include "buttons/sort.html" with col='dns' text='Dns' %}</th>
<th>{% include "buttons/sort.html" with col='ip' text='Ipv4' %}</th>
<th>{% include "buttons/sort.html" with col='loc' text='Localisation' %}</th>
<th>{% include "buttons/sort.html" with col='ports' text='Ports' %}</th>
<th>{% include "buttons/sort.html" with col='stack' text='Stack' %}</th>
<th>Id interne stack</th>
<th>Détails</th>
<th></th>
</tr>
......
......@@ -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
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment