summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2024-03-15 11:07:20 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2024-03-15 11:07:20 +0100
commit94713861e74a6c05ea45d3a78a77421b4d98b044 (patch)
tree6b7e5ddb411d7b102caf69974e18ad2213285f2a
parent15db286c0331de14a5eaf098b61d66590ac3cae3 (diff)
downloadIshtar-94713861e74a6c05ea45d3a78a77421b4d98b044.tar.bz2
Ishtar-94713861e74a6c05ea45d3a78a77421b4d98b044.zip
🐛 archaeological files - force cached label and complete ID regeneration (refs #5790)
-rw-r--r--archaeological_files/models.py10
-rw-r--r--archaeological_files/templates/ishtar/sheet_file.html4
-rw-r--r--archaeological_files/wizards.py20
3 files changed, 25 insertions, 9 deletions
diff --git a/archaeological_files/models.py b/archaeological_files/models.py
index 264773c1b..513dbace2 100644
--- a/archaeological_files/models.py
+++ b/archaeological_files/models.py
@@ -35,6 +35,7 @@ from ishtar_common.utils import (
cached_label_changed,
get_cache,
get_current_year,
+ get_generated_id,
m2m_historization_changed,
)
@@ -53,7 +54,6 @@ from ishtar_common.models import (
ValueGetter,
MainItem,
OperationType,
- get_generated_id,
post_save_cache,
Document,
HistoryModel,
@@ -1322,6 +1322,14 @@ class File(
updated = True
self.auto_external_id = True
self.external_id = external_id
+ complete_identifier = get_generated_id("file_complete_identifier", self)
+ if complete_identifier != self.complete_identifier:
+ updated = True
+ self.complete_identifier = complete_identifier
+ cached_label = self._generate_cached_label()
+ if cached_label != self.cached_label:
+ updated = True
+ self.cached_label = cached_label
if updated:
self._cached_label_checked = False
self.save()
diff --git a/archaeological_files/templates/ishtar/sheet_file.html b/archaeological_files/templates/ishtar/sheet_file.html
index 587aa45ab..30a428262 100644
--- a/archaeological_files/templates/ishtar/sheet_file.html
+++ b/archaeological_files/templates/ishtar/sheet_file.html
@@ -42,9 +42,11 @@
{% include "ishtar/blocks/window_image.html" %}
<div class="card-body">
<div class="card-text">
- {% if item.complete_identifier %}<p class="window-refs"
+ {% if item.complete_identifier and item.complete_identifier != item.cached_label %}<p class="window-refs"
title="{% trans 'Complete identifier' %}">
<strong>{{ item.complete_identifier }}</strong></p>{% endif %}
+ {% if item.cached_label %}
+ <p class="window-refs"><strong>{{ item.cached_label }}</strong></p>{% endif %}
<p class='window-refs'>{{item.full_internal_ref|default:''}}</p>
<p class='window-refs'>{{item.internal_reference|default:''}}</p>
<p class='window-refs'>{{item.name|default:''}}</p>
diff --git a/archaeological_files/wizards.py b/archaeological_files/wizards.py
index b89023877..8178e1c11 100644
--- a/archaeological_files/wizards.py
+++ b/archaeological_files/wizards.py
@@ -18,9 +18,8 @@
# See the file COPYING for details.
from django.conf import settings
-from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Max
-from ishtar_common.utils import ugettext_lazy as _
+from ishtar_common.utils import ugettext_lazy as _, get_generated_id
from ishtar_common.forms import reverse_lazy
from ishtar_common.wizards import ClosingWizard, SearchWizard, MultipleDeletionWizard
@@ -28,7 +27,7 @@ from archaeological_operations.wizards import (
OperationWizard,
OperationAdministrativeActWizard,
)
-from archaeological_operations.models import AdministrativeAct, Parcel
+from archaeological_operations.models import AdministrativeAct
from . import models
@@ -140,14 +139,14 @@ class FileWizard(OperationWizard):
"""
Make numeric_reference unique
"""
- r = super(FileWizard, self).done(form_list, return_object=True, **kwargs)
- if type(r) not in (list, tuple) or len(r) != 2:
+ r = super().done(form_list, return_object=True, **kwargs)
+ if not isinstance(r, (list, tuple)) or len(r) != 2:
return r
obj, res = r
+ changed = False
# numeric_reference check
if not self.modification:
numeric_reference = obj.numeric_reference
- changed = False
while (
obj.__class__.objects.filter(
numeric_reference=numeric_reference, year=obj.year
@@ -159,7 +158,14 @@ class FileWizard(OperationWizard):
changed = True
if changed:
obj.numeric_reference = numeric_reference
- obj.save()
+ cached_label = obj._generate_cached_label()
+ if cached_label != obj.cached_label:
+ obj.cached_label = cached_label
+ changed = True
+ if changed:
+ if hasattr(obj, "no_post_process"):
+ obj.no_post_process()
+ obj.save()
return res