fix vacant is null
[auf_rh_dae.git] / project / rh / templatetags / change_list.py
CommitLineData
a9f403cf
JPC
1from django.template import Library
2from django.db import connection
3from django import forms
4
5register = Library()
6
7@register.simple_tag
8def query_string_builder(cl, name, value):
9 return cl.get_query_string({name: value})
10
11@register.simple_tag
12def add_selected(cl, key, value):
13 return 'selected="selected" ' if key in cl.params and cl.params[key] == value else ''
14
15@register.inclusion_tag('admin/rh/annee_select.html')
16def recherche_par_annees(cl):
a9f403cf
JPC
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, '')
25
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""",
31 }))
a975f5fa 32 annee = forms.ChoiceField(choices=((cl.get_query_string({'annee': a}, ('periode', 'date_debut', 'date_fin')), a) for a in list_annees),
a9f403cf
JPC
33 widget=forms.Select(attrs = {
34 'onchange' : """window.location=window.location.pathname+this.options[this.selectedIndex].value""",
35 }))
36 date_debut = forms.DateField()
37 date_fin = forms.DateField()
38 params = cl.params
39 if 'periode' in params:
40 params['periode'] = cl.get_query_string({'periode': params['periode']})
41 if 'annee' in params:
42 params['annee'] = cl.get_query_string({'annee': params['annee']})
43 f = RechercheTemporelle(params)
44 return {
45 'form': f,
a975f5fa 46 'plage_date_querystring': cl.get_query_string(remove=('annee', 'periode'))
a9f403cf 47 }