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
commit5134f84b99674294d60d90d74ca979afd2ee40ec (patch)
treed1dd7549f0a9d11e1170157ed1700f9930caf91d /archaeological_files/models.py
parente7ba80e10c861b3e2222cc43c9a399d76b59a48f (diff)
downloadIshtar-5134f84b99674294d60d90d74ca979afd2ee40ec.tar.bz2
Ishtar-5134f84b99674294d60d90d74ca979afd2ee40ec.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={}):