mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-25 16:33:47 +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
|
to the column and order requested. It's used with a dict of possible
|
||||||
values and associated model_fields """
|
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 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
|
# The syntax to describe the sort to apply is a dict where the keys are
|
||||||
# to use as order field in the request. A 'default' might be provided to
|
# the url value and the values are a list of model field name to use to
|
||||||
# specify what to do if the requested col doesn't match any keys.
|
# 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 = {
|
USERS_INDEX = {
|
||||||
'name': 'name',
|
'name': ['name'],
|
||||||
'surname': 'surname',
|
'surname': ['surname'],
|
||||||
'pseudo': 'pseudo',
|
'pseudo': ['pseudo'],
|
||||||
'room': 'room',
|
'room': ['room'],
|
||||||
'default': 'pseudo'
|
'default': ['state', 'pseudo']
|
||||||
}
|
}
|
||||||
USERS_INDEX_BAN = {
|
USERS_INDEX_BAN = {
|
||||||
'user': 'user__pseudo',
|
'user': ['user__pseudo'],
|
||||||
'start': 'date_start',
|
'start': ['date_start'],
|
||||||
'end': 'date_end',
|
'end': ['date_end'],
|
||||||
'default': 'date_end'
|
'default': ['-date_end']
|
||||||
}
|
}
|
||||||
USERS_INDEX_WHITE = {
|
USERS_INDEX_WHITE = {
|
||||||
'user': 'user__pseudo',
|
'user': ['user__pseudo'],
|
||||||
'start': 'date_start',
|
'start': ['date_start'],
|
||||||
'end': 'date_end',
|
'end': ['date_end'],
|
||||||
'default': 'date_end'
|
'default': ['-date_end']
|
||||||
}
|
}
|
||||||
MACHINES_INDEX = {
|
MACHINES_INDEX = {
|
||||||
'name': 'name',
|
'name': ['name'],
|
||||||
'default': 'pk'
|
'default': ['pk']
|
||||||
}
|
}
|
||||||
COTISATIONS_INDEX = {
|
COTISATIONS_INDEX = {
|
||||||
'user': 'user__pseudo',
|
'user': ['user__pseudo'],
|
||||||
'paiement': 'paiement__moyen',
|
'paiement': ['paiement__moyen'],
|
||||||
'date': 'date',
|
'date': ['date'],
|
||||||
'default': 'date'
|
'default': ['-date']
|
||||||
}
|
}
|
||||||
COTISATIONS_CONTROL = {
|
COTISATIONS_CONTROL = {
|
||||||
'name': 'user__name',
|
'name': ['user__name'],
|
||||||
'surname': 'user__surname',
|
'surname': ['user__surname'],
|
||||||
'paiement': 'paiement',
|
'paiement': ['paiement'],
|
||||||
'date': 'date',
|
'date': ['date'],
|
||||||
'valid': 'valid',
|
'valid': ['valid'],
|
||||||
'control': 'control',
|
'control': ['control'],
|
||||||
'default': 'date'
|
'default': ['-date']
|
||||||
}
|
}
|
||||||
TOPOLOGIE_INDEX = {
|
TOPOLOGIE_INDEX = {
|
||||||
'dns': 'switch_interface__domain__name',
|
'dns': ['switch_interface__domain__name'],
|
||||||
'ip': 'switch_interface__ipv4__ipv4',
|
'ip': ['switch_interface__ipv4__ipv4'],
|
||||||
'loc': 'location',
|
'loc': ['location'],
|
||||||
'ports': 'number',
|
'ports': ['number'],
|
||||||
'stack': 'stack__name',
|
'stack': ['stack__name'],
|
||||||
'default': 'switch_interface__domain__name'
|
'default': ['location', 'stack', 'stack_member_id']
|
||||||
}
|
}
|
||||||
TOPOLOGIE_INDEX_PORT = {
|
TOPOLOGIE_INDEX_PORT = {
|
||||||
'port': 'port',
|
'port': ['port'],
|
||||||
'room': 'room__name',
|
'room': ['room__name'],
|
||||||
'interface': 'machine_interface__domain__name',
|
'interface': ['machine_interface__domain__name'],
|
||||||
'related': 'related__switch__name',
|
'related': ['related__switch__name'],
|
||||||
'radius': 'radius',
|
'radius': ['radius'],
|
||||||
'vlan': 'vlan_force__name',
|
'vlan': ['vlan_force__name'],
|
||||||
'default': 'port'
|
'default': ['port']
|
||||||
}
|
}
|
||||||
TOPOLOGIE_INDEX_ROOM = {
|
TOPOLOGIE_INDEX_ROOM = {
|
||||||
'name': 'name',
|
'name': ['name'],
|
||||||
'default': 'name'
|
'default': ['name']
|
||||||
}
|
}
|
||||||
TOPOLOGIE_INDEX_STACK = {
|
TOPOLOGIE_INDEX_STACK = {
|
||||||
'name': 'name',
|
'name': ['name'],
|
||||||
'id': 'stack_id',
|
'id': ['stack_id'],
|
||||||
'default': 'stack_id'
|
'default': ['stack_id'],
|
||||||
}
|
}
|
||||||
LOGS_INDEX = {
|
LOGS_INDEX = {
|
||||||
'date': 'revision__date_created',
|
'date': ['revision__date_created'],
|
||||||
'default': 'revision__date_created'
|
'default': ['-revision__date_created'],
|
||||||
}
|
}
|
||||||
LOGS_STATS_LOGS = {
|
LOGS_STATS_LOGS = {
|
||||||
'author': 'user__name',
|
'author': ['user__name'],
|
||||||
'date': 'date_created',
|
'date': ['date_created'],
|
||||||
'default': 'date_created'
|
'default': ['-date_created']
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@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
|
""" Check if the given values are possible and add .order_by() and
|
||||||
a .reverse() as specified according to those values """
|
a .reverse() as specified according to those values """
|
||||||
model_field = criterion.get(col, None)
|
fields = values.get(col, None)
|
||||||
if not model_field:
|
if not fields:
|
||||||
model_field = criterion.get('default', None)
|
fields = values.get('default', [])
|
||||||
if not model_field:
|
request = request.order_by(*fields)
|
||||||
return request
|
if order == 'desc':
|
||||||
|
return request.reverse()
|
||||||
else:
|
else:
|
||||||
if order == 'desc':
|
return request
|
||||||
return request.order_by(model_field).reverse()
|
|
||||||
else:
|
|
||||||
return request.order_by(model_field)
|
|
||||||
|
|
|
@ -157,7 +157,7 @@ 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 = SortTable.sort(
|
||||||
room_list,
|
room_list,
|
||||||
request.GET.get('col'),
|
request.GET.get('col'),
|
||||||
|
|
|
@ -575,7 +575,7 @@ 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 = SortTable.sort(
|
||||||
users_list,
|
users_list,
|
||||||
request.GET.get('col'),
|
request.GET.get('col'),
|
||||||
|
|
Loading…
Reference in a new issue