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