diff options
Diffstat (limited to 'archaeological_operations/forms.py')
| -rw-r--r-- | archaeological_operations/forms.py | 75 | 
1 files changed, 75 insertions, 0 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index 78e5a4ed4..bb743372d 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -306,6 +306,81 @@ if FILES_AVAILABLE:                                                 associated_model=File),               validators=[valid_id(File)], required=False) +SLICING = (("month",_(u"months")), ('year',_(u"years")),) + +DATE_SOURCE = (('creation',_(u"Creation date")), +               ("start",_(u"Start of field work"))) + +PREVENTIVE_RESARCH = (('all', _('All')), +                      ('preventive', _(u"Preventive")), +                      ('research', _(u"Research")),) + +class DashboardForm(forms.Form): +    slicing = forms.ChoiceField(label=_("Slicing"), choices=SLICING, +                              required=False) +    department_detail = forms.BooleanField(label=_("Department detail"), +                              required=False) +    date_source = forms.ChoiceField(label=_("Date get from"), +                            choices=DATE_SOURCE, required=False) +    preventive_research = forms.ChoiceField(label=_("Preventive/Research"), +                                    choices=PREVENTIVE_RESARCH, required=False) +    operation_type = forms.ChoiceField(label=_("Operation type"), choices=[], +                                       required=False) +    operator = forms.ChoiceField(label=_("Operator"), 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) +    with_report = forms.BooleanField(label=_("With reports"), required=False) +    with_finds = forms.BooleanField(label=_("With finds"), required=False) + +    def __init__(self, *args, **kwargs): +        if 'prefix' not in kwargs: +            kwargs['prefix'] = 'operations' +        super(DashboardForm, self).__init__(*args, **kwargs) +        self.fields['operation_type'].choices = models.OperationType.get_types() +        self.fields['operator'].choices = [('', '--')] +        self.fields['operator'].choices += [(orga.pk, orga.name) +            for orga in Organization.objects.filter(operator__isnull=False)\ +                                            .order_by('name').distinct().all()] + +    def get_show_detail(self): +        return hasattr(self, 'cleaned_data') and \ +           self.cleaned_data.get('department_detail') + +    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('preventive_research'): +            preventive_research = self.cleaned_data['preventive_research'] +            if preventive_research == 'preventive': +                fltr['file_type__preventive'] = True +            elif preventive_research == 'preventive': +                fltr['file_type__preventive'] = False +        if self.cleaned_data.get('operation_type'): +            fltr['operation_type_id'] = self.cleaned_data['operation_type'] +        if self.cleaned_data.get('operator'): +            fltr['operator_id'] = self.cleaned_data['operator'] +        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'] +        if self.cleaned_data.get('with_report'): +            fltr['report_delivery_date__isnull'] = False +        if self.cleaned_data.get('with_finds'): +            fltr['context_record__base_finds__isnull'] = False +        return fltr +  class OperationFormGeneral(forms.Form):      form_label = _(u"General")      base_model = 'archaeological_site'  | 
