mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-05 01:16:27 +00:00
Passage du search en GET + proprification du nom des variables
This commit is contained in:
parent
0ed60c64fd
commit
f8992ca0d8
4 changed files with 40 additions and 47 deletions
|
@ -28,18 +28,18 @@ from django import forms
|
||||||
from django.forms import Form
|
from django.forms import Form
|
||||||
from django.forms import ModelForm
|
from django.forms import ModelForm
|
||||||
|
|
||||||
CHOICES = (
|
CHOICES_USER = (
|
||||||
('0', 'Actifs'),
|
('0', 'Actifs'),
|
||||||
('1', 'Désactivés'),
|
('1', 'Désactivés'),
|
||||||
('2', 'Archivés'),
|
('2', 'Archivés'),
|
||||||
)
|
)
|
||||||
|
|
||||||
CHOICES2 = (
|
CHOICES_CO = (
|
||||||
(1, 'Active'),
|
(1, 'Active'),
|
||||||
("", 'Désactivée'),
|
("", 'Désactivée'),
|
||||||
)
|
)
|
||||||
|
|
||||||
CHOICES3 = (
|
CHOICES_AFF = (
|
||||||
('0', 'Utilisateurs'),
|
('0', 'Utilisateurs'),
|
||||||
('1', 'Machines'),
|
('1', 'Machines'),
|
||||||
('2', 'Factures'),
|
('2', 'Factures'),
|
||||||
|
@ -51,12 +51,12 @@ CHOICES3 = (
|
||||||
|
|
||||||
|
|
||||||
class SearchForm(Form):
|
class SearchForm(Form):
|
||||||
search_field = forms.CharField(label = 'Search', max_length = 100)
|
query = forms.CharField(label = 'Search', max_length = 100)
|
||||||
|
|
||||||
class SearchFormPlus(Form):
|
class SearchFormPlus(Form):
|
||||||
search_field = forms.CharField(label = 'Search', max_length = 100, required=False)
|
query = forms.CharField(label = 'Search', max_length = 100, required=False)
|
||||||
filtre = forms.MultipleChoiceField(label="Filtre utilisateurs", required=False, widget =forms.CheckboxSelectMultiple,choices=CHOICES)
|
user_state = forms.MultipleChoiceField(label="Filtre utilisateurs", required=False, widget =forms.CheckboxSelectMultiple,choices=CHOICES_USER)
|
||||||
connexion = forms.MultipleChoiceField(label="Filtre connexion", required=False, widget =forms.CheckboxSelectMultiple,choices=CHOICES2)
|
co_state = forms.MultipleChoiceField(label="Filtre connexion", required=False, widget =forms.CheckboxSelectMultiple,choices=CHOICES_CO)
|
||||||
affichage = forms.MultipleChoiceField(label="Filtre affichage", required=False, widget =forms.CheckboxSelectMultiple,choices=CHOICES3)
|
aff = forms.MultipleChoiceField(label="Filtre affichage", required=False, widget =forms.CheckboxSelectMultiple,choices=CHOICES_AFF)
|
||||||
date_deb = forms.DateField(required=False, label="Date de début", help_text='DD/MM/YYYY', input_formats=['%d/%m/%Y'])
|
start = 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")
|
end = forms.DateField(required=False, help_text='DD/MM/YYYY', input_formats=['%d/%m/%Y'], label="Date de fin")
|
||||||
|
|
|
@ -28,11 +28,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
{% block title %}Recherche{% endblock %}
|
{% block title %}Recherche{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% bootstrap_form_errors searchform %}
|
{% bootstrap_form_errors search_form %}
|
||||||
|
|
||||||
<form class="form" method="post">
|
<form class="form">
|
||||||
{% csrf_token %}
|
{% bootstrap_form search_form %}
|
||||||
{% bootstrap_form searchform %}
|
|
||||||
{% bootstrap_button "Search" button_type="submit" icon="search" %}
|
{% bootstrap_button "Search" button_type="submit" icon="search" %}
|
||||||
</form>
|
</form>
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -40,33 +40,28 @@ from cotisations.models import Facture
|
||||||
from search.models import SearchForm, SearchFormPlus
|
from search.models import SearchForm, SearchFormPlus
|
||||||
from preferences.models import GeneralOption
|
from preferences.models import GeneralOption
|
||||||
|
|
||||||
def form(ctx, template, request):
|
def search_result(search_form, type, request):
|
||||||
c = ctx
|
start = None
|
||||||
c.update(csrf(request))
|
end = None
|
||||||
return render(request, template, c)
|
user_state = []
|
||||||
|
co_state = []
|
||||||
def search_result(search, type, request):
|
|
||||||
date_deb = None
|
|
||||||
date_fin = None
|
|
||||||
states=[]
|
|
||||||
co=[]
|
|
||||||
aff = []
|
aff = []
|
||||||
if(type):
|
if(type):
|
||||||
aff = search.cleaned_data['affichage']
|
aff = search_form.cleaned_data['aff']
|
||||||
co = search.cleaned_data['connexion']
|
co_state = search_form.cleaned_data['co_state']
|
||||||
states = search.cleaned_data['filtre']
|
user_state = search_form.cleaned_data['user_state']
|
||||||
date_deb = search.cleaned_data['date_deb']
|
start = search_form.cleaned_data['start']
|
||||||
date_fin = search.cleaned_data['date_fin']
|
end = search_form.cleaned_data['end']
|
||||||
date_query = Q()
|
date_query = Q()
|
||||||
if aff==[]:
|
if aff==[]:
|
||||||
aff = ['0','1','2','3','4','5','6']
|
aff = ['0','1','2','3','4','5','6']
|
||||||
if date_deb != None:
|
if start != None:
|
||||||
date_query = date_query & Q(date__gte=date_deb)
|
date_query = date_query & Q(date__gte=start)
|
||||||
if date_fin != None:
|
if end != None:
|
||||||
date_query = date_query & Q(date__lte=date_fin)
|
date_query = date_query & Q(date__lte=end)
|
||||||
search = search.cleaned_data['search_field']
|
search = search_form.cleaned_data['query']
|
||||||
query1 = Q()
|
query1 = Q()
|
||||||
for s in states:
|
for s in user_state:
|
||||||
query1 = query1 | Q(state = s)
|
query1 = query1 | Q(state = s)
|
||||||
|
|
||||||
connexion = []
|
connexion = []
|
||||||
|
@ -121,14 +116,14 @@ def search_result(search, type, request):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def search(request):
|
def search(request):
|
||||||
search = SearchForm(request.POST or None)
|
search_form = SearchForm(request.GET or None)
|
||||||
if search.is_valid():
|
if search_form.is_valid():
|
||||||
return form(search_result(search, False, request), 'search/index.html',request)
|
return render(request, 'search/index.html', search_result(search_form, False, request))
|
||||||
return form({'searchform' : search}, 'search/search.html', request)
|
return render(request, 'search/search.html', {'search_form' : search_form})
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def searchp(request):
|
def searchp(request):
|
||||||
search = SearchFormPlus(request.POST or None)
|
search_form = SearchFormPlus(request.GET or None)
|
||||||
if search.is_valid():
|
if search_form.is_valid():
|
||||||
return form(search_result(search, True, request), 'search/index.html',request)
|
return render(request, 'search/index.html', search_result(search_form, True, request))
|
||||||
return form({'searchform' : search}, 'search/search.html', request)
|
return render(request, 'search/search.html', {'search_form' : search_form})
|
||||||
|
|
|
@ -72,8 +72,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
<div class="col-sm-3 col-md-3 navbar-right">
|
<div class="col-sm-3 col-md-3 navbar-right">
|
||||||
<form action="{% url "search:search"%}" method="POST" class="navbar-form" role="search">
|
<form action="{% url "search:search"%}" class="navbar-form" role="search">
|
||||||
{% csrf_token %}
|
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input type="text" class="form-control" placeholder="Search" name="search_field" id="search-term">
|
<input type="text" class="form-control" placeholder="Search" name="search_field" id="search-term">
|
||||||
<div class="input-group-btn">
|
<div class="input-group-btn">
|
||||||
|
|
Loading…
Reference in a new issue