summaryrefslogtreecommitdiff
path: root/archaeological_finds
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_finds')
-rw-r--r--archaeological_finds/forms.py4
-rw-r--r--archaeological_finds/forms_treatments.py48
2 files changed, 50 insertions, 2 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py
index bdb602606..c0f44423d 100644
--- a/archaeological_finds/forms.py
+++ b/archaeological_finds/forms.py
@@ -61,7 +61,7 @@ from archaeological_finds.forms_treatments import TreatmentSelect, \
AdministrativeActTreatmentFileFormSelection, \
AdministrativeActTreatmentFileModifForm, SourceTreatmentFormSelection, \
SourceTreatmentFileFormSelection, TreatmentSourceFormSelection, \
- TreatmentFileSourceFormSelection
+ TreatmentFileSourceFormSelection, DashboardForm as DashboardTreatmentForm
__all__ = [
'TreatmentSelect', 'TreatmentFormSelection', 'BaseTreatmentForm',
@@ -75,7 +75,7 @@ __all__ = [
'AdministrativeActTreatmentFormSelection',
'AdministrativeActTreatmentFileModifForm', 'SourceTreatmentFormSelection',
'SourceTreatmentFileFormSelection', 'TreatmentSourceFormSelection',
- 'TreatmentFileSourceFormSelection',
+ 'TreatmentFileSourceFormSelection', 'DashboardTreatmentForm',
'RecordFormSelection', 'FindForm', 'DateForm', 'DatingFormSet',
'FindSelect', 'FindFormSelection', 'FindFormSelectionWarehouseModule',
'MultipleFindFormSelection', 'MultipleFindFormSelectionWarehouseModule',
diff --git a/archaeological_finds/forms_treatments.py b/archaeological_finds/forms_treatments.py
index b3ad8b115..be62fc1d0 100644
--- a/archaeological_finds/forms_treatments.py
+++ b/archaeological_finds/forms_treatments.py
@@ -277,6 +277,54 @@ class TreatmentDeletionForm(FinalForm):
u"lost!")
confirm_end_msg = _(u"Would you like to delete this treatment?")
+SLICING = (("month", _(u"months")), ('year', _(u"years")),)
+
+PREVENTIVE_RESARCH = (('all', _('All')),
+ ('preventive', _(u"Preventive")),
+ ('research', _(u"Research")),)
+
+DATE_SOURCE = (("start", _(u"Start date")), ("end", _(u"Closing 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)
+ treatment_type = forms.ChoiceField(label=_("Treatment type"), choices=[],
+ required=False)
+ after = forms.DateField(label=_(u"Date after"),
+ widget=widgets.JQueryDate, required=False)
+ before = forms.DateField(label=_(u"Date before"),
+ widget=widgets.JQueryDate, required=False)
+
+ def __init__(self, *args, **kwargs):
+ if 'prefix' not in kwargs:
+ kwargs['prefix'] = 'treatments'
+ super(DashboardForm, self).__init__(*args, **kwargs)
+ self.fields['treatment_type'].choices = \
+ models.TreatmentType.get_types()
+
+ def get_date_source(self):
+ date_source = 'history'
+ 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 {}
+ fltr = {}
+ date_source = self.get_date_source()
+ if self.cleaned_data.get('treatment_type'):
+ fltr['treatment_types__pk'] = self.cleaned_data['treatment_type']
+ if self.cleaned_data.get('after'):
+ fltr[date_source + '_date__gte'] = self.cleaned_data['after']
+ if self.cleaned_data.get('before'):
+ fltr[date_source + '_date__lte'] = self.cleaned_data['before']
+ return fltr
+
# administrative act treatment