summaryrefslogtreecommitdiff
path: root/archaeological_finds/models_finds.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-01-29 12:15:51 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-01-29 12:15:51 +0100
commitd1ccd3fe6f240882b2158e046b4e7908a814930f (patch)
tree26118a3e75bd8047de57caae9927ce533709dd80 /archaeological_finds/models_finds.py
parente059936f31f789b564f262cf7ef04ecccabd1d45 (diff)
downloadIshtar-d1ccd3fe6f240882b2158e046b4e7908a814930f.tar.bz2
Ishtar-d1ccd3fe6f240882b2158e046b4e7908a814930f.zip
Treatments: add a view to get all non modif treatments
- manage go back in the modi treatment hierarchy
Diffstat (limited to 'archaeological_finds/models_finds.py')
-rw-r--r--archaeological_finds/models_finds.py31
1 files changed, 24 insertions, 7 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 6fe56afe5..ccf42952f 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -1354,12 +1354,14 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms,
operations_lbl.admin_order_field = \
"base_finds__context_record__operation__cached_label"
- def _get_treatments(self, model, rel='upstream', limit=None):
+ def _get_treatments(self, model, rel='upstream', limit=None, count=False):
treatments, findtreats = [], []
q = model.objects.filter(
find_id=self.pk).order_by(
'-treatment__year', '-treatment__index', '-treatment__start_date',
'-treatment__end_date')
+ if count:
+ return q.count()
for findtreat in q.distinct().all():
if findtreat.pk in findtreats:
continue
@@ -1371,12 +1373,6 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms,
treatments.append((q.all(), findtreat.treatment))
return treatments
- @property
- def weight_string(self):
- if not self.weight:
- return ""
- return "{} {}".format(self.weight, self.weight_unit or "")
-
def upstream_treatments(self, limit=None):
from archaeological_finds.models_treatments import \
FindUpstreamTreatments
@@ -1398,6 +1394,27 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms,
def all_treatments(self):
return self.upstream_treatments() + self.downstream_treatments()
+ def non_modif_treatments(self, limit=None):
+ from archaeological_finds.models_treatments import \
+ FindNonModifTreatments
+ return self._get_treatments(FindNonModifTreatments, 'finds',
+ limit=limit)
+
+ def non_modif_treatments_count(self):
+ from archaeological_finds.models_treatments import \
+ FindNonModifTreatments
+ return self._get_treatments(FindNonModifTreatments, 'finds',
+ count=True)
+
+ def limited_non_modif_treatments(self):
+ return self.non_modif_treatments(15)
+
+ @property
+ def weight_string(self):
+ if not self.weight:
+ return ""
+ return "{} {}".format(self.weight, self.weight_unit or "")
+
def get_department(self):
bf = self.get_first_base_find()
if not bf: