summaryrefslogtreecommitdiff
path: root/archaeological_files/models.py
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/models.py
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/models.py')
-rw-r--r--archaeological_files/models.py25
1 files changed, 14 insertions, 11 deletions
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={}):