summaryrefslogtreecommitdiff
path: root/archaeological_files
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@proxience.com>2014-10-16 20:34:20 +0200
committerÉtienne Loks <etienne.loks@proxience.com>2014-10-16 20:34:20 +0200
commite96320dc97ee2befd7deed6e518b9237a1441727 (patch)
treed1dd7549f0a9d11e1170157ed1700f9930caf91d /archaeological_files
parent709db764b4cb98ca7a4aa88aab4c4006d50201d5 (diff)
downloadIshtar-e96320dc97ee2befd7deed6e518b9237a1441727.tar.bz2
Ishtar-e96320dc97ee2befd7deed6e518b9237a1441727.zip
Dashboards - graphs: allow to choose source of the date (creation or reception)
Diffstat (limited to 'archaeological_files')
-rw-r--r--archaeological_files/forms.py16
-rw-r--r--archaeological_files/models.py25
2 files changed, 28 insertions, 13 deletions
diff --git a/archaeological_files/forms.py b/archaeological_files/forms.py
index e3b480a57..4364829b2 100644
--- a/archaeological_files/forms.py
+++ b/archaeological_files/forms.py
@@ -123,10 +123,14 @@ class FileFormSelection(forms.Form):
return cleaned_data
SLICING = (('year',_(u"years")), ("month",_(u"months")))
+DATE_SOURCE = (('creation',_(u"Creation date")),
+ ("reception",_(u"Reception 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)
file_type = forms.ChoiceField(label=_("File type"), choices=[],
required=False)
saisine_type = forms.ChoiceField(label=_("Saisine type"), choices=[],
@@ -141,18 +145,26 @@ class DashboardForm(forms.Form):
self.fields['saisine_type'].choices = models.SaisineType.get_types()
self.fields['file_type'].choices = models.FileType.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 {}
+ date_source = self.get_date_source()
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']
+ fltr[date_source+'_date__gte'] = self.cleaned_data['after']
if self.cleaned_data.get('before'):
- fltr['creation_date__lte'] = self.cleaned_data['before']
+ fltr[date_source+'_date__lte'] = self.cleaned_data['before']
return fltr
class FileFormGeneral(forms.Form):
diff --git a/archaeological_files/models.py b/archaeological_files/models.py
index a1e8912f4..70570e145 100644
--- a/archaeological_files/models.py
+++ b/archaeological_files/models.py
@@ -230,32 +230,35 @@ class File(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem):
return sorted(owns.all(), key=lambda x:x.cached_label)
@classmethod
- def get_periods(cls, slice='year', fltr={}):
- q = cls.objects
+ def get_periods(cls, slice='year', fltr={}, date_source='creation'):
+ date_var = date_source + '_date'
+ q = cls.objects.filter(**{date_var+'__isnull':False})
if fltr:
q = q.filter(**fltr)
if slice == 'year':
- return [res['year'] for res in list(q.values('year'
+ return [res[date_var].year for res in list(q.values(date_var
).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'
+ return [(res[date_var].year, res[date_var].month)
+ for res in list(q.values(date_var
).annotate(Count("id")).order_by())]
return []
@classmethod
- def get_by_year(cls, year, fltr={}):
- q = cls.objects
+ def get_by_year(cls, year, fltr={}, date_source='creation'):
+ date_var = date_source + '_date'
+ q = cls.objects.filter(**{date_var+'__isnull':False})
if fltr:
q = q.filter(**fltr)
- return q.filter(year=year)
+ return q.filter(**{date_var+'__year':year})
@classmethod
- def get_by_month(cls, year, month, fltr={}):
- q = cls.objects
+ def get_by_month(cls, year, month, fltr={}, date_source='creation'):
+ date_var = date_source + '_date'
+ q = cls.objects.filter(**{date_var+'__isnull':False})
if fltr:
q = q.filter(**fltr)
- return q.filter(creation_date__year=year, creation_date__month=month)
+ return q.filter(**{date_var+'__year':year, date_var+'__month':month})
@classmethod
def get_total_number(cls, fltr={}):