diff --git a/search/__pycache__/models.cpython-34.pyc b/search/__pycache__/models.cpython-34.pyc index 103fb5a6..e3d86e05 100644 Binary files a/search/__pycache__/models.cpython-34.pyc and b/search/__pycache__/models.cpython-34.pyc differ diff --git a/search/__pycache__/views.cpython-34.pyc b/search/__pycache__/views.cpython-34.pyc index da15f326..620bb971 100644 Binary files a/search/__pycache__/views.cpython-34.pyc and b/search/__pycache__/views.cpython-34.pyc differ 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)])