diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2014-10-15 01:14:31 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2014-10-15 01:14:31 +0200 |
commit | 97c69aab0038bbd067017a9a43ad67e477abc2e3 (patch) | |
tree | a28c33c17f007b692f8071aba453fd13b6d0745e /archaeological_files/forms.py | |
parent | 65a99f54a4220bd18f5c4337e8d99ce5d24e665b (diff) | |
download | Ishtar-97c69aab0038bbd067017a9a43ad67e477abc2e3.tar.bz2 Ishtar-97c69aab0038bbd067017a9a43ad67e477abc2e3.zip |
Dashboard: implement a form to choose criteria for the graph display
Diffstat (limited to 'archaeological_files/forms.py')
-rw-r--r-- | archaeological_files/forms.py | 33 |
1 files changed, 33 insertions, 0 deletions
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, |