1 from django
.template
import Library
2 from django
.db
import connection
3 from django
import forms
8 def query_string_builder(cl
, name
, value
):
9 return cl
.get_query_string({name
: value
})
12 def add_selected(cl
, key
, value
):
13 return 'selected="selected" ' if key
in cl
.params
and cl
.params
[key
] == value
else ''
15 @register.inclusion_tag('admin/rh/annee_select.html')
16 def recherche_par_annees(cl
):
17 cursor
= connection
.cursor()
18 cursor
.execute("SELECT year(date_debut) FROM rh_dossier WHERE year(date_debut) IS NOT NULL GROUP BY year(date_debut)")
19 set_annees
= set(row
[0] for row
in cursor
.fetchall())
20 cursor
.execute("SELECT year(date_fin) FROM rh_dossier WHERE year(date_fin) IS NOT NULL GROUP BY year(date_fin)")
21 for row
in cursor
.fetchall():
22 set_annees
.add(row
[0])
23 list_annees
= list(set_annees
)
24 list_annees
.insert(0, '')
26 class RechercheTemporelle(forms
.Form
):
27 periode
= forms
.ChoiceField(
28 choices
=((cl
.get_query_string({'periode': p
}, ('annee', 'date_debut', 'date_fin')), p
) for p
in cl
.PERIODE_CHOICE
),
29 widget
=forms
.Select(attrs
= {
30 'onchange' : """window.location=window.location.pathname+this.options[this.selectedIndex].value""",
32 annee
= forms
.ChoiceField(choices
=((cl
.get_query_string({'annee': a
}, ('periode', 'date_debut', 'date_fin')), a
) for a
in list_annees
),
33 widget
=forms
.Select(attrs
= {
34 'onchange' : """window.location=window.location.pathname+this.options[this.selectedIndex].value""",
36 date_debut
= forms
.DateField()
37 date_fin
= forms
.DateField()
39 if 'periode' in params
:
40 params
['periode'] = cl
.get_query_string({'periode': params
['periode']})
42 params
['annee'] = cl
.get_query_string({'annee': params
['annee']})
43 f
= RechercheTemporelle(params
)
46 'plage_date_querystring': cl
.get_query_string(remove
=('annee', 'periode'))