diff options
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 |
commit | 95d01d904eb18b8ec60f494150cbdced277dbf7d (patch) | |
tree | a28c33c17f007b692f8071aba453fd13b6d0745e /archaeological_operations/models.py | |
parent | 79b6f50c48ed7bf8bb56f9d2439f64aeab2861ee (diff) | |
download | Ishtar-95d01d904eb18b8ec60f494150cbdced277dbf7d.tar.bz2 Ishtar-95d01d904eb18b8ec60f494150cbdced277dbf7d.zip |
Dashboard: implement a form to choose criteria for the graph display
Diffstat (limited to 'archaeological_operations/models.py')
-rw-r--r-- | archaeological_operations/models.py | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index d865c1ff9..c7a8c94ac 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -335,21 +335,32 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem): return (max_val + 1) if max_val else 1 @classmethod - def get_years(cls): - max_year = datetime.date.today().year + 1 - return [res['year'] for res in list( - cls.objects.exclude( year__isnull=True - ).exclude(year__gt=max_year - ).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': + max_year = datetime.date.today().year + 1 + return [res['year'] for res in list( + q.exclude( year__isnull=True + ).exclude(year__gt=max_year + ).values('year' + ).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_total_number(cls, fltr={}): + q = cls.objects + if fltr: + q = q.filter(**fltr) + return q.count() year_index_lbl = _(u"Operation code") @property |