From 95d01d904eb18b8ec60f494150cbdced277dbf7d Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 15 Oct 2014 01:14:31 +0200 Subject: Dashboard: implement a form to choose criteria for the graph display --- archaeological_files/forms.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'archaeological_files/forms.py') diff --git a/archaeological_files/forms.py b/archaeological_files/forms.py index 4ff483a75..e3b480a57 100644 --- a/archaeological_files/forms.py +++ b/archaeological_files/forms.py @@ -122,6 +122,39 @@ class FileFormSelection(forms.Form): raise forms.ValidationError(_(u"You should select a file.")) return cleaned_data +SLICING = (('year',_(u"years")), ("month",_(u"months"))) + +class DashboardForm(forms.Form): + slicing = forms.ChoiceField(label=_("Slicing"), choices=SLICING, + required=False) + file_type = forms.ChoiceField(label=_("File type"), choices=[], + required=False) + saisine_type = forms.ChoiceField(label=_("Saisine type"), choices=[], + required=False) + after = forms.DateField(label=_(u"Creation date after"), + widget=widgets.JQueryDate, required=False) + before = forms.DateField(label=_(u"Creation date before"), + widget=widgets.JQueryDate, required=False) + + def __init__(self, *args, **kwargs): + super(DashboardForm, self).__init__(*args, **kwargs) + self.fields['saisine_type'].choices = models.SaisineType.get_types() + self.fields['file_type'].choices = models.FileType.get_types() + + def get_filter(self): + if not hasattr(self, 'cleaned_data') or not self.cleaned_data: + return {} + fltr = {} + if self.cleaned_data.get('saisine_type'): + fltr['saisine_type_id'] = self.cleaned_data['saisine_type'] + if self.cleaned_data.get('file_type'): + fltr['file_type_id'] = self.cleaned_data['file_type'] + if self.cleaned_data.get('after'): + fltr['creation_date__gte'] = self.cleaned_data['after'] + if self.cleaned_data.get('before'): + fltr['creation_date__lte'] = self.cleaned_data['before'] + return fltr + class FileFormGeneral(forms.Form): form_label = _("General") associated_models = {'in_charge':Person, -- cgit v1.2.3