diff options
Diffstat (limited to 'archaeological_files/forms.py')
| -rw-r--r-- | archaeological_files/forms.py | 16 | 
1 files changed, 14 insertions, 2 deletions
| diff --git a/archaeological_files/forms.py b/archaeological_files/forms.py index e3b480a57..4364829b2 100644 --- a/archaeological_files/forms.py +++ b/archaeological_files/forms.py @@ -123,10 +123,14 @@ class FileFormSelection(forms.Form):          return cleaned_data  SLICING = (('year',_(u"years")), ("month",_(u"months"))) +DATE_SOURCE = (('creation',_(u"Creation date")), +               ("reception",_(u"Reception date")))  class DashboardForm(forms.Form):      slicing = forms.ChoiceField(label=_("Slicing"), choices=SLICING,                                required=False) +    date_source = forms.ChoiceField(label=_("Date get from"), +                            choices=DATE_SOURCE, required=False)      file_type = forms.ChoiceField(label=_("File type"), choices=[],                                    required=False)      saisine_type = forms.ChoiceField(label=_("Saisine type"), choices=[], @@ -141,18 +145,26 @@ class DashboardForm(forms.Form):          self.fields['saisine_type'].choices = models.SaisineType.get_types()          self.fields['file_type'].choices = models.FileType.get_types() +    def get_date_source(self): +        date_source = 'creation' +        if hasattr(self, 'cleaned_data') and \ +           self.cleaned_data.get('date_source'): +            date_source = self.cleaned_data['date_source'] +        return date_source +      def get_filter(self):          if not hasattr(self, 'cleaned_data') or not self.cleaned_data:              return {} +        date_source = self.get_date_source()          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'] +            fltr[date_source+'_date__gte'] = self.cleaned_data['after']          if self.cleaned_data.get('before'): -            fltr['creation_date__lte'] = self.cleaned_data['before'] +            fltr[date_source+'_date__lte'] = self.cleaned_data['before']          return fltr  class FileFormGeneral(forms.Form): | 
