diff --git a/search/models.py b/search/models.py
index 8d1fa0e4..f0900728 100644
--- a/search/models.py
+++ b/search/models.py
@@ -28,18 +28,18 @@ from django import forms
from django.forms import Form
from django.forms import ModelForm
-CHOICES = (
+CHOICES_USER = (
('0', 'Actifs'),
('1', 'Désactivés'),
('2', 'Archivés'),
)
-CHOICES2 = (
+CHOICES_CO = (
(1, 'Active'),
("", 'Désactivée'),
)
-CHOICES3 = (
+CHOICES_AFF = (
('0', 'Utilisateurs'),
('1', 'Machines'),
('2', 'Factures'),
@@ -51,12 +51,12 @@ CHOICES3 = (
class SearchForm(Form):
- search_field = forms.CharField(label = 'Search', max_length = 100)
+ query = forms.CharField(label = 'Search', max_length = 100)
class SearchFormPlus(Form):
- search_field = forms.CharField(label = 'Search', max_length = 100, required=False)
- filtre = forms.MultipleChoiceField(label="Filtre utilisateurs", required=False, widget =forms.CheckboxSelectMultiple,choices=CHOICES)
- connexion = forms.MultipleChoiceField(label="Filtre connexion", required=False, widget =forms.CheckboxSelectMultiple,choices=CHOICES2)
- affichage = forms.MultipleChoiceField(label="Filtre affichage", required=False, widget =forms.CheckboxSelectMultiple,choices=CHOICES3)
- 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")
+ query = forms.CharField(label = 'Search', max_length = 100, required=False)
+ user_state = forms.MultipleChoiceField(label="Filtre utilisateurs", required=False, widget =forms.CheckboxSelectMultiple,choices=CHOICES_USER)
+ co_state = forms.MultipleChoiceField(label="Filtre connexion", required=False, widget =forms.CheckboxSelectMultiple,choices=CHOICES_CO)
+ aff = forms.MultipleChoiceField(label="Filtre affichage", required=False, widget =forms.CheckboxSelectMultiple,choices=CHOICES_AFF)
+ start = forms.DateField(required=False, label="Date de début", help_text='DD/MM/YYYY', input_formats=['%d/%m/%Y'])
+ end = forms.DateField(required=False, help_text='DD/MM/YYYY', input_formats=['%d/%m/%Y'], label="Date de fin")
diff --git a/search/templates/search/search.html b/search/templates/search/search.html
index adb5dd92..f97af015 100644
--- a/search/templates/search/search.html
+++ b/search/templates/search/search.html
@@ -28,11 +28,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% block title %}Recherche{% endblock %}
{% block content %}
-{% bootstrap_form_errors searchform %}
+{% bootstrap_form_errors search_form %}
-
diff --git a/search/views.py b/search/views.py
index 16c365d8..34421ac1 100644
--- a/search/views.py
+++ b/search/views.py
@@ -40,36 +40,31 @@ from cotisations.models import Facture
from search.models import SearchForm, SearchFormPlus
from preferences.models import GeneralOption
-def form(ctx, template, request):
- c = ctx
- c.update(csrf(request))
- return render(request, template, c)
-
-def search_result(search, type, request):
- date_deb = None
- date_fin = None
- states=[]
- co=[]
- aff=[]
+def search_result(search_form, type, request):
+ start = None
+ end = None
+ user_state = []
+ co_state = []
+ aff = []
if(type):
- aff = search.cleaned_data['affichage']
- co = search.cleaned_data['connexion']
- states = search.cleaned_data['filtre']
- date_deb = search.cleaned_data['date_deb']
- date_fin = search.cleaned_data['date_fin']
+ aff = search_form.cleaned_data['aff']
+ co_state = search_form.cleaned_data['co_state']
+ user_state = search_form.cleaned_data['user_state']
+ start = search_form.cleaned_data['start']
+ end = search_form.cleaned_data['end']
date_query = Q()
if aff==[]:
aff = ['0','1','2','3','4','5','6']
- if date_deb != None:
- date_query = date_query & Q(date__gte=date_deb)
- if date_fin != None:
- date_query = date_query & Q(date__lte=date_fin)
- search = search.cleaned_data['search_field']
+ if start != None:
+ date_query = date_query & Q(date__gte=start)
+ if end != None:
+ date_query = date_query & Q(date__lte=end)
+ search = search_form.cleaned_data['query']
query1 = Q()
- for s in states:
+ for s in user_state:
query1 = query1 | Q(state = s)
- connexion = []
+ connexion = []
recherche = {'users_list': None, 'machines_list' : [], 'facture_list' : None, 'ban_list' : None, 'white_list': None, 'port_list': None, 'switch_list': None}
@@ -121,14 +116,14 @@ def search_result(search, type, request):
@login_required
def search(request):
- search = SearchForm(request.POST or None)
- if search.is_valid():
- return form(search_result(search, False, request), 'search/index.html',request)
- return form({'searchform' : search}, 'search/search.html', request)
+ search_form = SearchForm(request.GET or None)
+ if search_form.is_valid():
+ return render(request, 'search/index.html', search_result(search_form, False, request))
+ return render(request, 'search/search.html', {'search_form' : search_form})
@login_required
def searchp(request):
- search = SearchFormPlus(request.POST or None)
- if search.is_valid():
- return form(search_result(search, True, request), 'search/index.html',request)
- return form({'searchform' : search}, 'search/search.html', request)
+ search_form = SearchFormPlus(request.GET or None)
+ if search_form.is_valid():
+ return render(request, 'search/index.html', search_result(search_form, True, request))
+ return render(request, 'search/search.html', {'search_form' : search_form})
diff --git a/templates/base.html b/templates/base.html
index 3d8cfea7..0e8c6187 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -72,8 +72,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endif %}