mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-25 08:23:46 +00:00
Sort : support des order_by sur plusieurs fields
et delete de deux order_by oublié dans les views
This commit is contained in:
parent
aae9370a55
commit
f139b5b2c4
3 changed files with 65 additions and 65 deletions
126
re2o/utils.py
126
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
|
||||
|
|
|
@ -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'),
|
||||
|
|
|
@ -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'),
|
||||
|
|
Loading…
Reference in a new issue