From a8590ecbc0def5fe668aac175600c6d09057d698 Mon Sep 17 00:00:00 2001 From: Dalahro Date: Mon, 4 Jul 2016 00:03:33 +0200 Subject: [PATCH] Ajout d'un filtre sur l'utilisateur dans la recherche --- search/__pycache__/models.cpython-34.pyc | Bin 574 -> 1042 bytes search/__pycache__/views.cpython-34.pyc | Bin 1819 -> 1915 bytes search/models.py | 12 ++++++++++-- search/views.py | 6 +++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/search/__pycache__/models.cpython-34.pyc b/search/__pycache__/models.cpython-34.pyc index 103fb5a69f3a7caba657700a7a9082a8f6a1ffb2..e3d86e05fbfa51fa98b9a92cb4f2a8d001695226 100644 GIT binary patch literal 1042 zcmY*YJ8#=C5I$KCOSYW23D7Y}A3@g}Hb=qmH9!EQ z280F}q*p*xAT=R0OWg!vL25&2m%62O2STURZ4gyRT?k#&cOdlO1M`73;5#nX0B*xI zE>;7!1^w3UE$#{}LpkY;agiaiM>Clcu(}BF>-EUBQLHZ+m&$mpoReXmj51}sx$|*} z&doZD(Q=7jWgOjkXgiU^i8c&rlZQc`W1QJf6dZ^r(hMuWO*prRKT>8UFvK=62d=?H zuH<#Jx4N-2R~u3FfV&uGAy*1RZaR^cLR^QEKN21rI;{RU>~R2PZR;@XS`&NpMAiB{ zMlRF>Ws7*gg>p)hs-^KV5_~$&C$~rglq>l~kx0(EtDSBla>@6LJP}D2=e&^0StM-C zb5$KqX33Ce#TF)Y(6`U6TzL~N=26a<`Ks3G1ifBxhC?-y>Ac7zI-WSsR_*}{ z4$|P@Y*l~AA0^Y%RztZ_G>uapMXDA>c&>#Y>_^c>5sT6zO{&#vPh#0kxM0f9G{tD7 zwcTDJ@?~q0~`9p}Rwm*LU)PCO&oss6NJgP_Mgf2rEF+SKJ ztZ)r-A2-+HelNI;Ww2N*0?ChNL0Lpl-o?ZDm26<-HqOjN;TwC#D}1!|bX}2ET8BJ{ z=~~HJiR*;vR<=y}obU@0FUe3>9y^bxk!l8CYRjH71KND)KZlFh#L4q_6_jvQ6H@sKe|Bq_dfvI9D)N<^mD|j9|zlzzhIB CM=kyU diff --git a/search/__pycache__/views.cpython-34.pyc b/search/__pycache__/views.cpython-34.pyc index da15f32665fd982ee74eb83bfe3b2b2febf9531e..620bb971c27886ba206b8d97a2120f5c7648c543 100644 GIT binary patch delta 643 zcmY*Wzi-n(6#ky=vt!3ep){(BR0?89D=`PLmBI{2L5frfmC|!d+(;1nK#gQ8L&U&r ziG`gVG4qd@m6?%+h3}jaRGr@M@4fHt-RJI~ZuBeeM7tknqr>29G;`){0E+U6l7A7P z08&5;&K+d$#YmHJ@b(roun?5Y2vQddAUhK4d(aNHN~b9>a2W`UvXIin#T^t59>3T^ z>7j6KLDTVAp34CN(?g7mk2FBqYO2akT0kt)zw{4m5c~@`X5U^$;fx$UF8U}GId)JI z!&xDU04B1UxHHFUnSRHJuPB!+Efn(=4e^cN(6DV8@N%Yoc`;I2#tflxx{HBcvwK{)7+P$zLVXQ`m-_lDzuNQ%S#A0X_&=8Q;oka_+I#kN z_`LQ{#}kt!b(|;1*~#mp({VDsLS3Z|PS*{QbWo`F^?p delta 547 zcmZ`$O-sW-5Pg$mH*K0$(H2oqD^f%dJXr)UqJlRSD)c0Nbfaw))HH&HgdTGDlA{;@ zf_U>U_z(IY^ytNlv(XkW66Wp9o0omV>{scrM3eGY17EgqRtEZz2JL1=6_%Wnh{cp@1*p+X!<|rq(4Oom;>8mM+Aw zNT`q4zy%PSxL-nKVCQHaF{@4Zc|;aMMkh$X_p z?@*D<=I80$A=Ce%atMp)WVR}gdL*D6K5VE0AAFySx+>~TBqkbKn=L_=m>wI^qgCzF zXjT7cx!+hG-y2L?2m6h~f!p;?gI4?ayyIP|mlLZ@GY&t6=)T;`Yu9dg;5UuGY9$;pkQwKx0%Pmx{DTl5v)CnI`yKp(&$6 OK`q^ppHxdX?9Fd)4`!tR diff --git a/search/models.py b/search/models.py index 8de5d9ba..909a641a 100644 --- a/search/models.py +++ b/search/models.py @@ -6,6 +6,14 @@ from django.forms import ModelForm from users.models import User # Create your models here. -class SearchForm(Form): - search_field = forms.CharField(label = 'Search', max_length = 100) +CHOICES = ( + ('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") diff --git a/search/views.py b/search/views.py index 4e2211dc..f4fb9537 100644 --- a/search/views.py +++ b/search/views.py @@ -22,8 +22,12 @@ def search(request): if request.method == 'POST': search = SearchForm(request.POST or None) if search.is_valid(): + states = search.cleaned_data['filtre'] 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 = [] for user in users: connexion.append([user, has_access(user)])