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

Ajoute le sort des colonnes sur la recherche

This commit is contained in:
Maël Kervella 2017-11-02 00:25:24 +00:00
parent d37099f11c
commit 742d905e83
3 changed files with 73 additions and 49 deletions

View file

@ -36,7 +36,9 @@ def url_insert_param(url="", **kwargs):
Return the URL with some specific parameters inserted into the query Return the URL with some specific parameters inserted into the query
part. If a URL has already some parameters, those requested will be part. If a URL has already some parameters, those requested will be
modified if already exisiting or will be added and the other parameters modified if already exisiting or will be added and the other parameters
will stay unmodified. will stay unmodified. If parameters with the same name are already in the
URL and a value is specified for this parameter, it will replace all
existing parameters.
**Tag name**:: **Tag name**::
@ -82,18 +84,21 @@ def url_insert_param(url="", **kwargs):
# Get existing parameters in the url # Get existing parameters in the url
params = {} params = {}
if '?' in url: if '?' in url:
url, params = url.split('?', maxsplit=1) url, parameters = url.split('?', maxsplit=1)
params = { for parameter in parameters.split('&'):
p[:p.find('=')]: p[p.find('=')+1:] for p in params.split('&') p_name, p_value = parameter.split('=', maxsplit=1)
} if p_name not in params:
params[p_name] = []
params[p_name].append(p_value)
# Add the request parameters to the list of parameters # Add the request parameters to the list of parameters
for key, value in kwargs.items(): for key, value in kwargs.items():
params[key] = value params[key] = [value]
# Write the url # Write the url
url += '?' url += '?'
for param, value in params.items(): for param, value_list in params.items():
for value in value_list:
url += str(param) + '=' + str(value) + '&' url += str(param) + '=' + str(value) + '&'
# Remove the last '&' (or '?' if no parameters) # Remove the last '&' (or '?' if no parameters)

View file

@ -22,10 +22,8 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import models
from django import forms from django import forms
from django.forms import Form from django.forms import Form
from django.forms import ModelForm
CHOICES_USER = ( CHOICES_USER = (
('0', 'Actifs'), ('0', 'Actifs'),
@ -43,6 +41,7 @@ CHOICES_AFF = (
('5', 'Ports'), ('5', 'Ports'),
) )
def initial_choices(c): def initial_choices(c):
return [i[0] for i in c] return [i[0] for i in c]
@ -50,10 +49,6 @@ def initial_choices(c):
class SearchForm(Form): class SearchForm(Form):
q = forms.CharField(label='Search', max_length=100) q = forms.CharField(label='Search', max_length=100)
def clean(self):
cleaned_data = super(SearchForm, self).clean()
q = cleaned_data.get('q', '')
class SearchFormPlus(Form): class SearchFormPlus(Form):
q = forms.CharField( q = forms.CharField(
@ -87,11 +82,3 @@ class SearchFormPlus(Form):
input_formats=['%d/%m/%Y'], input_formats=['%d/%m/%Y'],
label="Date de fin" label="Date de fin"
) )
def clean(self):
cleaned_data = super(SearchFormPlus, self).clean()
q = cleaned_data.get('q')
u = cleaned_data.get('u')
a = cleaned_data.get('a')
s = cleaned_data.get('s')
e = cleaned_data.get('e')

View file

@ -45,6 +45,7 @@ from search.forms import (
CHOICES_AFF, CHOICES_AFF,
initial_choices initial_choices
) )
from re2o.utils import SortTable
def get_results(query, request, filters={}): def get_results(query, request, filters={}):
start = filters.get('s', None) start = filters.get('s', None)
@ -96,9 +97,13 @@ def get_results(query, request, filters={}):
) & user_state_filter ) & user_state_filter
if not request.user.has_perms(('cableur',)): if not request.user.has_perms(('cableur',)):
filter_user_list &= Q(id=request.user.id) filter_user_list &= Q(id=request.user.id)
results['users_list'] = User.objects.filter( results['users_list'] = User.objects.filter(filter_user_list)
filter_user_list results['users_list'] = SortTable.sort(
).order_by('state', 'surname').distinct()[:max_result] results['users_list'],
request.GET.get('col'),
request.GET.get('order'),
SortTable.USERS_INDEX
)
# Machines # Machines
if '1' in aff: if '1' in aff:
@ -119,20 +124,28 @@ def get_results(query, request, filters={}):
) )
if not request.user.has_perms(('cableur',)): if not request.user.has_perms(('cableur',)):
filter_machine_list &= Q(machine__user__id=request.user.id) filter_machine_list &= Q(machine__user__id=request.user.id)
results['machines_list'] = Machine.objects.filter( results['machines_list'] = Machine.objects.filter(filter_machine_list)
filter_machine_list results['machines_list'] = SortTable.sort(
).order_by('name').distinct()[:max_result] results['machines_list'],
request.GET.get('col'),
request.GET.get('order'),
SortTable.MACHINES_INDEX
)
# Factures # Factures
if '2' in aff: if '2' in aff:
date_filter = Q() filter_facture_list = users_filter
if start != None: if start != None:
date_filter &= Q(date__gte=start) filter_facture_list &= Q(date__gte=start)
if end != None: if end != None:
date_filter &= Q(date__lte=end) filter_facture_list &= Q(date__lte=end)
results['facture_list'] = Facture.objects.filter( results['facture_list'] = Facture.objects.filter(filter_facture_list)
users_filter & date_filter results['facture_list'] = SortTable.sort(
).order_by('date').distinct()[:max_result] results['facture_list'],
request.GET.get('col'),
request.GET.get('order'),
SortTable.COTISATIONS_INDEX
)
# Bans # Bans
if '3' in aff: if '3' in aff:
@ -153,9 +166,13 @@ def get_results(query, request, filters={}):
) | ( ) | (
Q(date_start__gte=end) & Q(date_end__lte=end) Q(date_start__gte=end) & Q(date_end__lte=end)
) )
results['ban_list'] = Ban.objects.filter( results['ban_list'] = Ban.objects.filter(users_filter & date_filter)
users_filter & date_filter results['ban_list'] = SortTable.sort(
).order_by('date_end').distinct()[:max_result] results['ban_list'],
request.GET.get('col'),
request.GET.get('order'),
SortTable.USERS_INDEX_BAN
)
# Whitelists # Whitelists
if '4' in aff: if '4' in aff:
@ -176,21 +193,36 @@ def get_results(query, request, filters={}):
) | ( ) | (
Q(date_start__gte=end) & Q(date_end__lte=end) Q(date_start__gte=end) & Q(date_end__lte=end)
) )
results['white_list'] = Whitelist.objects.filter( results['white_list'] = Whitelist.objects.filter(users_filter & date_filter)
users_filter & date_filter results['white_list'] = SortTable.sort(
).order_by('date_end').distinct()[:max_result] results['white_list'],
request.GET.get('col'),
request.GET.get('order'),
SortTable.USERS_INDEX_WHITE
)
# Switch ports # Switch ports
if '5' in aff and request.user.has_perms(('cableur',)): if '5' in aff and request.user.has_perms(('cableur',)):
results['port_list'] = Port.objects.filter( results['port_list'] = Port.objects.filter(details__icontains=query)
details__icontains=query results['port_list'] = SortTable.sort(
).order_by('switch', 'port').distinct()[:max_result] results['port_list'],
request.GET.get('col'),
request.GET.get('order'),
SortTable.TOPOLOGIE_INDEX_PORT
)
# Switches # Switches
if '6' in aff and request.user.has_perms(('cableur')): if '6' in aff and request.user.has_perms(('cableur')):
results['switch_list'] = Switch.objects.filter( results['switch_list'] = Switch.objects.filter(details__icontains=query)
details__icontains=query results['switch_list'] = SortTable.sort(
).order_by('stack', 'stack_member_id').distinct()[:max_result] results['switch_list'],
request.GET.get('col'),
request.GET.get('order'),
SortTable.TOPOLOGIE_INDEX
)
for r in results.keys():
results[r] = results[r].distinct()[:max_result]
results.update({'max_result': max_result}) results.update({'max_result': max_result})