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_finds | |
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_finds')
-rw-r--r-- | archaeological_finds/models.py | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py index cdc87ea95..2f4c59668 100644 --- a/archaeological_finds/models.py +++ b/archaeological_finds/models.py @@ -233,22 +233,29 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): return bf.context_record.operation.get_town_label() @classmethod - def get_years(cls): - years = set() - finds = cls.objects.filter(downstream_treatment__isnull=True) - for find in finds: - bi = find.base_finds.all() - if not bi: - continue - bi = bi[0] - if bi.context_record.operation.start_date: - yr = bi.context_record.operation.start_date.year - years.add(yr) + def get_periods(cls, slice='year', fltr={}): + q = cls.objects + if fltr: + q = q.filter(**fltr) + if slice == 'year': + years = set() + finds = q.filter(downstream_treatment__isnull=True) + for find in finds: + bi = find.base_finds.all() + if not bi: + continue + bi = bi[0] + if bi.context_record.operation.start_date: + yr = bi.context_record.operation.start_date.year + years.add(yr) return list(years) @classmethod - def get_by_year(cls, year): - return cls.objects.filter(downstream_treatment__isnull=True, + def get_by_year(cls, year, fltr={}): + q = cls.objects + if fltr: + q = q.filter(**fltr) + return q.filter(downstream_treatment__isnull=True, base_finds__context_record__operation__start_date__year=year) @classmethod @@ -270,8 +277,11 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): base_finds__context_record__operation__pk=operation_id) @classmethod - def get_total_number(cls): - return cls.objects.filter(downstream_treatment__isnull=True).count() + def get_total_number(cls, fltr={}): + q = cls.objects + if fltr: + q = q.filter(**fltr) + return q.filter(downstream_treatment__isnull=True).count() def duplicate(self, user): dct = dict([(attr, getattr(self, attr)) for attr in ('order', 'label', |