import avec project.
[auf_rh_dae.git] / project / rh / templatetags / change_list.py
CommitLineData
a9f403cf 1from django import forms
75f0e87b
DB
2from django.contrib.admin import widgets as adminwidgets
3from django.db import connection
4from django.template import Library
5
6from project.rh import change_list as pcl
a9f403cf
JPC
7
8register = Library()
9
10@register.simple_tag
11def query_string_builder(cl, name, value):
12 return cl.get_query_string({name: value})
13
14@register.simple_tag
15def add_selected(cl, key, value):
16 return 'selected="selected" ' if key in cl.params and cl.params[key] == value else ''
17
18@register.inclusion_tag('admin/rh/annee_select.html')
19def recherche_par_annees(cl):
910e39e5
OL
20 list_annees = cl.get_annees()
21 statut_choices = [(cl.get_query_string(remove=(pcl.KEY_STATUT,)), 'Tous')] + [(cl.get_query_string({pcl.KEY_STATUT : p }, (pcl.KEY_ANNEE, pcl.KEY_DATE_DEBUT, pcl.KEY_DATE_FIN)), p) for p in cl.STATUT_CHOICES]
22 annee_choices = [(cl.get_query_string(remove=(pcl.KEY_ANNEE,)), 'Toutes')] + [(cl.get_query_string({pcl.KEY_ANNEE : a}, (pcl.KEY_STATUT , pcl.KEY_DATE_DEBUT, pcl.KEY_DATE_FIN)), a) for a in list_annees]
a17e2236 23 on_change = """window.location=window.location.pathname+this.options[this.selectedIndex].value"""
a9f403cf
JPC
24
25 class RechercheTemporelle(forms.Form):
a17e2236
OL
26 statut = forms.ChoiceField(choices=statut_choices, widget=forms.Select(attrs = {'onchange' : on_change}))
27 annee = forms.ChoiceField(choices=annee_choices, widget=forms.Select(attrs = {'onchange' : on_change}))
28 date_debut = forms.DateField(widget=adminwidgets.AdminDateWidget)
29 date_fin = forms.DateField(widget=adminwidgets.AdminDateWidget)
30
31 params = cl.params.copy()
32 if pcl.KEY_STATUT in params:
33 params[pcl.KEY_STATUT] = cl.get_query_string({pcl.KEY_STATUT: params[pcl.KEY_STATUT]})
34 if pcl.KEY_ANNEE in params:
35 params[pcl.KEY_ANNEE] = cl.get_query_string({pcl.KEY_ANNEE: params[pcl.KEY_ANNEE]})
a9f403cf
JPC
36 f = RechercheTemporelle(params)
37 return {
38 'form': f,
a17e2236 39 'plage_date_querystring': cl.get_query_string(remove=(pcl.KEY_ANNEE, pcl.KEY_STATUT))
a9f403cf 40 }