diff options
| -rw-r--r-- | archaeological_finds/forms.py | 4 | ||||
| -rw-r--r-- | archaeological_finds/forms_treatments.py | 51 | ||||
| -rw-r--r-- | ishtar_common/templates/ishtar/dashboards/dashboard_main_detail.html | 2 | ||||
| -rw-r--r-- | ishtar_common/views.py | 12 | 
4 files changed, 57 insertions, 12 deletions
| diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index c0f44423d..ee010094b 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -61,7 +61,8 @@ from archaeological_finds.forms_treatments import TreatmentSelect, \      AdministrativeActTreatmentFileFormSelection, \      AdministrativeActTreatmentFileModifForm, SourceTreatmentFormSelection, \      SourceTreatmentFileFormSelection, TreatmentSourceFormSelection, \ -    TreatmentFileSourceFormSelection, DashboardForm as DashboardTreatmentForm +    TreatmentFileSourceFormSelection, DashboardForm as DashboardTreatmentForm, \ +    DashboardTreatmentFileForm  __all__ = [      'TreatmentSelect', 'TreatmentFormSelection', 'BaseTreatmentForm', @@ -76,6 +77,7 @@ __all__ = [      'AdministrativeActTreatmentFileModifForm', 'SourceTreatmentFormSelection',      'SourceTreatmentFileFormSelection', 'TreatmentSourceFormSelection',      'TreatmentFileSourceFormSelection', 'DashboardTreatmentForm', +    'DashboardTreatmentFileForm',      'RecordFormSelection', 'FindForm', 'DateForm', 'DatingFormSet',      'FindSelect', 'FindFormSelection', 'FindFormSelectionWarehouseModule',      'MultipleFindFormSelection', 'MultipleFindFormSelectionWarehouseModule', diff --git a/archaeological_finds/forms_treatments.py b/archaeological_finds/forms_treatments.py index be62fc1d0..58429f4c9 100644 --- a/archaeological_finds/forms_treatments.py +++ b/archaeological_finds/forms_treatments.py @@ -279,10 +279,6 @@ class TreatmentDeletionForm(FinalForm):  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")),) @@ -306,7 +302,7 @@ class DashboardForm(forms.Form):              models.TreatmentType.get_types()      def get_date_source(self): -        date_source = 'history' +        date_source = 'start'          if hasattr(self, 'cleaned_data') and \                  self.cleaned_data.get('date_source'):              date_source = self.cleaned_data['date_source'] @@ -532,6 +528,51 @@ class TreatmentFileDeletionForm(FinalForm):      confirm_msg = _(u"Are you sure you want to delete this treatment request?")      confirm_end_msg = _(u"Would you like to delete this treatment request?") +DATE_SOURCE_FILE = ( +    ("creation", _(u"Creation date")), +    ("reception", _(u"Reception date")), +    ("end", _(u"Closing date")),) + + +class DashboardTreatmentFileForm(forms.Form): +    slicing = forms.ChoiceField(label=_("Slicing"), choices=SLICING, +                                required=False) +    date_source = forms.ChoiceField( +        label=_("Date get from"), choices=DATE_SOURCE_FILE, required=False) +    treatmentfile_type = forms.ChoiceField(label=_("Treatment request 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'] = 'treatmentfiles' +        super(DashboardTreatmentFileForm, self).__init__(*args, **kwargs) +        self.fields['treatmentfile_type'].choices = \ +            models.TreatmentFileType.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 {} +        fltr = {} +        date_source = self.get_date_source() +        if self.cleaned_data.get('treatmentfile_type'): +            fltr['type__pk'] = self.cleaned_data['treatmentfile_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 +  class AdministrativeActTreatmentFileSelect(TableSelect):      year = forms.IntegerField(label=_("Year")) diff --git a/ishtar_common/templates/ishtar/dashboards/dashboard_main_detail.html b/ishtar_common/templates/ishtar/dashboards/dashboard_main_detail.html index c3a8a58a8..2650282ca 100644 --- a/ishtar_common/templates/ishtar/dashboards/dashboard_main_detail.html +++ b/ishtar_common/templates/ishtar/dashboards/dashboard_main_detail.html @@ -178,7 +178,7 @@ $('#search_{{unique_id}}').click(function (){      return false;  }); -{% if item_name == 'files' or item_name == "operations" or item_name == "treatments" or item_name == "treatment_types" %} +{% if item_name == 'files' or item_name == "operations" or item_name == "treatments" or item_name == "treatmentfiles" %}  load_jquerydate_{{item_name}}_after();  load_jquerydate_{{item_name}}_before();  {% endif %} diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 4aa452641..94e4c1582 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -63,7 +63,8 @@ from archaeological_finds.models import Find, Treatment, TreatmentFile, \  from archaeological_operations.forms import DashboardForm as DashboardFormOpe  from archaeological_files.forms import DashboardForm as DashboardFormFile -from archaeological_finds.forms import DashboardTreatmentForm +from archaeological_finds.forms import DashboardTreatmentForm, \ +    DashboardTreatmentFileForm  from ishtar_common.forms import FinalForm, FinalDeleteForm  from ishtar_common.widgets import JQueryAutoComplete @@ -1461,7 +1462,8 @@ def dashboard_main(request, dct, obj_id=None, *args, **kwargs):  DASHBOARD_FORMS = {      'files': DashboardFormFile, 'operations': DashboardFormOpe, -    'treatments': DashboardTreatmentForm +    'treatments': DashboardTreatmentForm, +    'treatmentfiles': DashboardTreatmentFileForm  } @@ -1478,9 +1480,9 @@ def dashboard_main_detail(request, item_name):      slicing, date_source, fltr, show_detail = 'year', None, {}, False      profile = models.get_current_profile()      has_form = (item_name == 'files' and profile.files) \ -            or item_name == 'operations' \ -            or (item_name in ('treatmentfiles', 'treatments') -                and profile.warehouse) +        or item_name == 'operations' \ +        or (item_name in ('treatmentfiles', 'treatments') +            and profile.warehouse)      if has_form:          slicing = 'month'      if item_name in DASHBOARD_FORMS: | 
