summaryrefslogtreecommitdiff
path: root/archaeological_files
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@proxience.com>2014-10-15 01:14:31 +0200
committerÉtienne Loks <etienne.loks@proxience.com>2014-10-15 01:14:31 +0200
commit95d01d904eb18b8ec60f494150cbdced277dbf7d (patch)
treea28c33c17f007b692f8071aba453fd13b6d0745e /archaeological_files
parent79b6f50c48ed7bf8bb56f9d2439f64aeab2861ee (diff)
downloadIshtar-95d01d904eb18b8ec60f494150cbdced277dbf7d.tar.bz2
Ishtar-95d01d904eb18b8ec60f494150cbdced277dbf7d.zip
Dashboard: implement a form to choose criteria for the graph display
Diffstat (limited to 'archaeological_files')
-rw-r--r--archaeological_files/forms.py33
-rw-r--r--archaeological_files/models.py36
2 files changed, 62 insertions, 7 deletions
diff --git a/archaeological_files/forms.py b/archaeological_files/forms.py
index 4ff483a75..e3b480a57 100644
--- a/archaeological_files/forms.py
+++ b/archaeological_files/forms.py
@@ -122,6 +122,39 @@ class FileFormSelection(forms.Form):
raise forms.ValidationError(_(u"You should select a file."))
return cleaned_data
+SLICING = (('year',_(u"years")), ("month",_(u"months")))
+
+class DashboardForm(forms.Form):
+ slicing = forms.ChoiceField(label=_("Slicing"), choices=SLICING,
+ required=False)
+ file_type = forms.ChoiceField(label=_("File type"), choices=[],
+ required=False)
+ saisine_type = forms.ChoiceField(label=_("Saisine type"), choices=[],
+ required=False)
+ after = forms.DateField(label=_(u"Creation date after"),
+ widget=widgets.JQueryDate, required=False)
+ before = forms.DateField(label=_(u"Creation date before"),
+ widget=widgets.JQueryDate, required=False)
+
+ def __init__(self, *args, **kwargs):
+ super(DashboardForm, self).__init__(*args, **kwargs)
+ self.fields['saisine_type'].choices = models.SaisineType.get_types()
+ self.fields['file_type'].choices = models.FileType.get_types()
+
+ def get_filter(self):
+ if not hasattr(self, 'cleaned_data') or not self.cleaned_data:
+ return {}
+ 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']
+ if self.cleaned_data.get('before'):
+ fltr['creation_date__lte'] = self.cleaned_data['before']
+ return fltr
+
class FileFormGeneral(forms.Form):
form_label = _("General")
associated_models = {'in_charge':Person,
diff --git a/archaeological_files/models.py b/archaeological_files/models.py
index 6d5390737..a1e8912f4 100644
--- a/archaeological_files/models.py
+++ b/archaeological_files/models.py
@@ -230,17 +230,39 @@ class File(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem):
return sorted(owns.all(), key=lambda x:x.cached_label)
@classmethod
- def get_years(cls):
- return [res['year'] for res in list(cls.objects.values('year').annotate(
- Count("id")).order_by())]
+ def get_periods(cls, slice='year', fltr={}):
+ q = cls.objects
+ if fltr:
+ q = q.filter(**fltr)
+ if slice == 'year':
+ return [res['year'] for res in list(q.values('year'
+ ).annotate(Count("id")).order_by())]
+ elif slice == 'month':
+ return [(res['creation_date'].year, res['creation_date'].month)
+ for res in list(q.values('creation_date'
+ ).annotate(Count("id")).order_by())]
+ return []
@classmethod
- def get_by_year(cls, year):
- return cls.objects.filter(year=year)
+ def get_by_year(cls, year, fltr={}):
+ q = cls.objects
+ if fltr:
+ q = q.filter(**fltr)
+ return q.filter(year=year)
@classmethod
- def get_total_number(cls):
- return cls.objects.count()
+ def get_by_month(cls, year, month, fltr={}):
+ q = cls.objects
+ if fltr:
+ q = q.filter(**fltr)
+ return q.filter(creation_date__year=year, creation_date__month=month)
+
+ @classmethod
+ def get_total_number(cls, fltr={}):
+ q = cls.objects
+ if fltr:
+ q = q.filter(**fltr)
+ return q.count()
def get_values(self, prefix=''):
values = super(File, self).get_values(prefix=prefix)