diff options
-rw-r--r-- | archaeological_finds/forms.py | 4 | ||||
-rw-r--r-- | archaeological_finds/forms_treatments.py | 48 | ||||
-rw-r--r-- | ishtar_common/models.py | 2 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/dashboards/dashboard_main_detail.html | 2 | ||||
-rw-r--r-- | ishtar_common/views.py | 23 |
5 files changed, 67 insertions, 12 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 diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 83cb25d46..44bc138eb 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1370,7 +1370,7 @@ class DashboardFormItem(object): return q.distinct('pk').count() -class Dashboard: +class Dashboard(object): def __init__(self, model, slice='year', date_source=None, show_detail=None, fltr={}): # don't provide date_source if it is not relevant diff --git a/ishtar_common/templates/ishtar/dashboards/dashboard_main_detail.html b/ishtar_common/templates/ishtar/dashboards/dashboard_main_detail.html index fd92578a2..c3a8a58a8 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"%} +{% if item_name == 'files' or item_name == "operations" or item_name == "treatments" or item_name == "treatment_types" %} load_jquerydate_{{item_name}}_after(); load_jquerydate_{{item_name}}_before(); {% endif %} diff --git a/ishtar_common/views.py b/ishtar_common/views.py index e8a2c9e12..4aa452641 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -63,6 +63,7 @@ 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 ishtar_common.forms import FinalForm, FinalDeleteForm from ishtar_common.widgets import JQueryAutoComplete @@ -1458,7 +1459,10 @@ def dashboard_main(request, dct, obj_id=None, *args, **kwargs): return render_to_response('ishtar/dashboards/dashboard_main.html', dct, context_instance=RequestContext(request)) -DASHBOARD_FORMS = {'files': DashboardFormFile, 'operations': DashboardFormOpe} +DASHBOARD_FORMS = { + 'files': DashboardFormFile, 'operations': DashboardFormOpe, + 'treatments': DashboardTreatmentForm +} def dashboard_main_detail(request, item_name): @@ -1473,8 +1477,11 @@ def dashboard_main_detail(request, item_name): form = None slicing, date_source, fltr, show_detail = 'year', None, {}, False profile = models.get_current_profile() - if (item_name == 'files' and profile.files) \ - or item_name == 'operations': + has_form = (item_name == 'files' and profile.files) \ + or item_name == 'operations' \ + or (item_name in ('treatmentfiles', 'treatments') + and profile.warehouse) + if has_form: slicing = 'month' if item_name in DASHBOARD_FORMS: if request.method == 'POST': @@ -1490,8 +1497,7 @@ def dashboard_main_detail(request, item_name): form = DASHBOARD_FORMS[item_name]() lbl, dashboard = None, None dashboard_kwargs = {} - if (item_name == 'files' and profile.files) \ - or item_name == 'operations': + if has_form: dashboard_kwargs = {'slice': slicing, 'fltr': fltr, 'show_detail': show_detail} # date_source is only relevant when the form has set one @@ -1515,12 +1521,13 @@ def dashboard_main_detail(request, item_name): elif item_name == 'treatmentfiles' and profile.warehouse: lbl, dashboard = ( _(u"Treatment requests"), - models.Dashboard(TreatmentFile, slice=slicing, fltr=fltr)) + models.Dashboard(TreatmentFile, **dashboard_kwargs)) elif item_name == 'treatments' and profile.warehouse: + if 'date_source' not in dashboard_kwargs: + dashboard_kwargs['date_source'] = 'start' lbl, dashboard = ( _(u"Treatments"), - models.Dashboard(Treatment, slice=slicing, fltr=fltr, - date_source='start')) + models.Dashboard(Treatment, **dashboard_kwargs)) if not lbl: raise Http404 dct = {'lbl': lbl, 'dashboard': dashboard, |