From 46799d5bca1f1d1f43e88e9d34817ae25221063c Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 4 Sep 2025 17:03:52 +0200 Subject: ✨ templates: clean and add fields for operations (refs #6435) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- archaeological_operations/models.py | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'archaeological_operations/models.py') diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index b7b955b80..301b9c6ca 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -1847,6 +1847,15 @@ class Operation( def get_document_containers_values(self, filtr, exclude) -> list: # Container value return self._get_containers_values(self.document_containers_q, filtr, exclude) + def get_finds_values(self, filtr, exclude) -> list: # finds value + if "operation" not in exclude: + exclude.append("operation") + finds = [] + for f in self.finds_q.exclude(base_finds__isnull=True).order_by( + "base_finds__context_record_id").distinct().all(): + finds.append(f.get_values(filtr=filtr, exclude=exclude, no_operation=True)) + return finds + def get_extra_values(self, prefix="", no_values=False, filtr=None, **kwargs): values = {} values = get_values_town_related(self, prefix, values, filtr=filtr) @@ -1856,10 +1865,17 @@ class Operation( containers = [] if (not filtr or ( f"{prefix}containers" in filtr or f"{prefix}all_containers" in filtr)) and ( - f"{prefix}containers" not in exclude + f"{prefix}containers" not in exclude and "containers" not in exclude ): containers = self.get_containers_values(filtr, exclude) values[f"{prefix}containers"] = containers[:] + finds = [] + if (not filtr or f"{prefix}finds" in filtr) and ( + f"{prefix}finds" not in exclude and not prefix.endswith("operation_")): + if "context_record" in exclude: + exclude.pop(exclude.index("context_record")) + finds = self.get_finds_values(filtr, exclude) + values[f"{prefix}finds"] = finds[:] document_containers = [] if (not filtr or ( f"{prefix}document_containers" in filtr or f"{prefix}all_containers" in filtr)) and ( @@ -1878,9 +1894,8 @@ class Operation( if prefix: return values # context_records only when there is no prefix - if ( - not filtr or "context_records" in filtr - ) and "context_records" not in exclude: + if (not filtr or "context_records" in filtr) and \ + "context_records" not in exclude: kwargs["no_base_finds"] = False values["context_records"] = [ cr.get_values(prefix=prefix, no_values=True, filtr=None, **kwargs) @@ -2137,6 +2152,15 @@ class Operation( finds__base_finds__context_record__operation=self ) + @property + def finds_q(self): # -> Find queryset + """ + Finds related to this operation + """ + Find = apps.get_model("archaeological_finds", "Find") + q = Find.objects.filter(base_finds__context_record__operation=self) + return q + @property def containers_q(self): # -> Container queryset """ -- cgit v1.2.3