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:35:23 +0100
commitcaa6d9bdead4783e5eac0a45d5b60ed86d54df45 (patch)
treea0179d9af2c8150ce15d4433e7e8122ad8cc5af3
parente0012a61bef172799dcfa703081fe917596ed978 (diff)
downloadIshtar-caa6d9bdead4783e5eac0a45d5b60ed86d54df45.tar.bz2
Ishtar-caa6d9bdead4783e5eac0a45d5b60ed86d54df45.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 210fd7996..f206e6628 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 4b7536735..57cdd9acf 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -1233,7 +1233,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 cf0db7d19..75a4e2d95 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()]
@@ -1127,7 +1127,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 23fe5b1a9..57d83c22c 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -65,7 +65,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
@@ -198,6 +198,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 7526edcec..0fe65356b 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -1843,8 +1843,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":
@@ -1886,9 +1892,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)