summaryrefslogtreecommitdiff
path: root/archaeological_operations
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2025-09-04 17:03:52 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2025-09-04 17:03:52 +0200
commit46799d5bca1f1d1f43e88e9d34817ae25221063c (patch)
treea56f84759a60b86ef28c4aca68311fc7fa942e14 /archaeological_operations
parent30303bbc898814a1e54eaba7410bdc9fc9669d60 (diff)
downloadIshtar-46799d5bca1f1d1f43e88e9d34817ae25221063c.tar.bz2
Ishtar-46799d5bca1f1d1f43e88e9d34817ae25221063c.zip
✨ templates: clean and add fields for operations (refs #6435)
Diffstat (limited to 'archaeological_operations')
-rw-r--r--archaeological_operations/models.py32
1 files changed, 28 insertions, 4 deletions
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)
@@ -2138,6 +2153,15 @@ class Operation(
)
@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
"""
Containers with finds related to this operation