mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Ajout d'un filtre sur l'utilisateur dans la recherche
This commit is contained in:
parent
4635ee05c8
commit
0fe552f029
4 changed files with 15 additions and 3 deletions
Binary file not shown.
Binary file not shown.
|
@ -6,6 +6,14 @@ from django.forms import ModelForm
|
||||||
from users.models import User
|
from users.models import User
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
|
||||||
class SearchForm(Form):
|
CHOICES = (
|
||||||
search_field = forms.CharField(label = 'Search', max_length = 100)
|
('0', 'Actifs'),
|
||||||
|
('1', 'Désactivés'),
|
||||||
|
('2', 'Archivés'),
|
||||||
|
)
|
||||||
|
|
||||||
|
class SearchForm(Form):
|
||||||
|
search_field = forms.CharField(label = 'Search', max_length = 100, required=False)
|
||||||
|
filtre = forms.MultipleChoiceField(label="Filtre utilisateur", required=False, widget =forms.CheckboxSelectMultiple,choices=CHOICES)
|
||||||
|
date_deb = forms.DateField(required=False, label="Date de début", help_text='DD/MM/YYYY', input_formats=['%d/%m/%Y'])
|
||||||
|
date_fin = forms.DateField(required=False, help_text='DD/MM/YYYY', input_formats=['%d/%m/%Y'], label="Date de fin")
|
||||||
|
|
|
@ -22,8 +22,12 @@ def search(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
search = SearchForm(request.POST or None)
|
search = SearchForm(request.POST or None)
|
||||||
if search.is_valid():
|
if search.is_valid():
|
||||||
|
states = search.cleaned_data['filtre']
|
||||||
search = search.cleaned_data['search_field']
|
search = search.cleaned_data['search_field']
|
||||||
users = User.objects.filter(Q(pseudo__icontains = search) | Q(name__icontains = search) | Q(surname__icontains = search))
|
query = Q()
|
||||||
|
for s in states:
|
||||||
|
query = query | Q(state = s)
|
||||||
|
users = User.objects.filter((Q(pseudo__icontains = search) | Q(name__icontains = search) | Q(surname__icontains = search)) & query)
|
||||||
connexion = []
|
connexion = []
|
||||||
for user in users:
|
for user in users:
|
||||||
connexion.append([user, has_access(user)])
|
connexion.append([user, has_access(user)])
|
||||||
|
|
Loading…
Reference in a new issue