diff options
| -rw-r--r-- | archaeological_context_records/models.py | 1 | ||||
| -rw-r--r-- | archaeological_finds/models_finds.py | 1 | ||||
| -rw-r--r-- | archaeological_operations/models.py | 2 | ||||
| -rw-r--r-- | ishtar_common/views_item.py | 14 | 
4 files changed, 14 insertions, 4 deletions
| diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 83c2d6b43..6b26825be 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -453,6 +453,7 @@ class ContextRecord(              ("activity__label", _("Activity")),              ("excavation_technic__label", _("Excavation technique")),              ("documents__source_type__label", _("Associated document type")), +            ("last_modified__year", _("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 0e4e89745..d825a8bb2 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -1114,6 +1114,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)")),          ]      )      STATISTIC_MODALITIES = [key for key, lbl in STATISTIC_MODALITIES_OPTIONS.items()] diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 691af56e1..7bc50d0b0 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -193,6 +193,7 @@ class ArchaeologicalSite(              ("periods__label", _("Periods")),              ("remains__label", _("Remains")),              ("documents__source_type__label", _("Associated document type")), +            ("last_modified__year", _("Modification (year)")),          ]      )      STATISTIC_MODALITIES = [key for key, lbl in STATISTIC_MODALITIES_OPTIONS.items()] @@ -813,6 +814,7 @@ class Operation(              ("documentation_received", _("Documentation received")),              ("finds_received", _("Finds received")),              ("documents__source_type__label", _("Associated document type")), +            ("last_modified__year", _("Modification (year)")),          ]      )      STATISTIC_MODALITIES = [key for key, lbl in STATISTIC_MODALITIES_OPTIONS.items()] diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index 31a16b672..5e689367b 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -29,6 +29,7 @@ from django.db.models import (      FileField,  )  from django.db.models.fields import FieldDoesNotExist +from django.db.models.functions import ExtractYear  from django.db.utils import ProgrammingError  from django.forms.models import model_to_dict  from django.http import HttpResponse @@ -1422,10 +1423,15 @@ def _format_modality(value):  def _get_json_stats(      items, stats_sum_variable, stats_modality_1, stats_modality_2, multiply=1  ): -    if stats_modality_2: -        q = items.values(stats_modality_1, stats_modality_2) -    else: -        q = items.values(stats_modality_1) +    q = items +    value_keys = [] +    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")])}) +        value_keys.append(stat) +    q = q.values(*value_keys)      if stats_sum_variable == "pk":          q = q.annotate(sum=Count("pk"))      else: | 
