summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2026-01-12 16:49:45 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2026-01-12 18:38:28 +0100
commitcee816ef28218edcf9d1a8405cd23878ac3514e0 (patch)
tree2a619248ea8e1f559184e04588c52e028a07d8ed
parent8efe927325b5f97308b44450d1ce2c9f9ac3465f (diff)
downloadIshtar-cee816ef28218edcf9d1a8405cd23878ac3514e0.tar.bz2
Ishtar-cee816ef28218edcf9d1a8405cd23878ac3514e0.zip
🐛 fix statistic evaluation for last modified and top container
-rw-r--r--archaeological_context_records/models.py2
-rw-r--r--archaeological_finds/models_finds.py2
-rw-r--r--archaeological_operations/models.py4
-rw-r--r--ishtar_common/utils.py3
-rw-r--r--ishtar_common/views_item.py16
5 files changed, 17 insertions, 10 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 21981fc78..d990cff09 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -583,7 +583,7 @@ class ContextRecord(
("activity__label", _("Activity")),
("excavation_technics__label", _("Excavation techniques")),
("documents__source_type__label", _("Associated document type")),
- ("last_modified__year", _("Modification (year)")),
+ ("last_modified__FILTERyear", _("Modification (year)")),
]
)
STATISTIC_MODALITIES = [key for key, lbl in STATISTIC_MODALITIES_OPTIONS.items()]
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 1a08eb171..cc89fedf1 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -1336,7 +1336,7 @@ class Find(
("alteration_causes__label", _("Alteration cause")),
("treatment_emergency__label", _("Treatment emergency")),
("documents__source_type__label", _("Associated document type")),
- ("last_modified__year", _("Modification (year)")),
+ ("last_modified__FILTERyear", _("Modification (year)")),
]
)
STATISTIC_MODALITIES = [key for key, lbl in STATISTIC_MODALITIES_OPTIONS.items()]
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 614ee69aa..d65f1b7bc 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -389,7 +389,7 @@ class ArchaeologicalSite(
("periods__label", _("Periods")),
("remains__label", _("Remains")),
("documents__source_type__label", _("Associated document type")),
- ("last_modified__year", _("Modification (year)")),
+ ("last_modified__FILTERyear", _("Modification (year)")),
]
)
STATISTIC_MODALITIES = [key for key, lbl in STATISTIC_MODALITIES_OPTIONS.items()]
@@ -1170,7 +1170,7 @@ class Operation(
("documentation_received", _("Documentation provided")),
("finds_received", _("Finds provided")),
("documents__source_type__label", _("Associated document type")),
- ("last_modified__year", _("Modification (year)")),
+ ("last_modified__FILTERyear", _("Modification (year)")),
]
)
STATISTIC_MODALITIES = [key for key, lbl in STATISTIC_MODALITIES_OPTIONS.items()]
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index bfe3928d2..9bfb28e62 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -67,7 +67,7 @@ from django.core.files import File
from django.core.files.storage import FileSystemStorage
from django.core.validators import EMPTY_VALUES, MaxValueValidator
from django.db import models
-from django.db.models import Func, Q
+from django.db.models import Func, Q, TextField
from django.db.models.functions import Length
from django.http import HttpResponseRedirect
from django.urls import reverse, NoReverseMatch
@@ -204,6 +204,7 @@ class SplitPart(Func):
PostgreSQL split part annotation
"""
function = 'split_part'
+ output_field = TextField()
arity = 3
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index 155c4c140..c5b85a6ee 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -2050,8 +2050,14 @@ def _get_json_stats_optimized(
for stat in (stats_modality_1, stats_modality_2):
if not stat:
continue
- if stat.endswith("__year"):
- q = q.annotate(**{stat: ExtractYear(stat[: -len("__year")])})
+ if stat.endswith("__FILTERyear"):
+ q = q.annotate(**{stat: ExtractYear(stat[:-len("__FILTERyear")])})
+ elif "__splitpart_" in stat:
+ st, args = stat.split("__splitpart_")
+ sep, index = args.split("_")
+ index = int(index)
+ stat = f"{st}_modality"
+ q = q.annotate(**{stat: SplitPart(F(st), Value(sep), index)})
value_keys.append(stat)
q = q.values(*value_keys)
if stats_sum_variable == "pk":
@@ -2093,9 +2099,9 @@ def _get_json_stats(
if not stat:
value_keys.append(stat)
continue
- if stat.endswith("__year"):
- q = q.annotate(**{stat: ExtractYear(stat[:-len("__year")])})
- if "__splitpart_" in stat:
+ if stat.endswith("__FILTERyear"):
+ q = q.annotate(**{stat: ExtractYear(stat[:-len("__FILTERyear")])})
+ elif "__splitpart_" in stat:
st, args = stat.split("__splitpart_")
sep, index = args.split("_")
index = int(index)