From fac19ea38fbd46bf6d6636e9d12b555269788019 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 7 Jun 2023 15:07:45 +0200 Subject: ⚡️ improve post treatments after imports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - check_cascade_update is now function which evaluate if cascade update is relevant - "_no_repost_save" attribute prevent a resave after post import - fix updat check for geo post save - add some logging --- archaeological_warehouse/models.py | 52 +++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'archaeological_warehouse') diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index 048f02d4d..392082ba9 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -19,6 +19,7 @@ from collections import OrderedDict import datetime +import logging import uuid from django.conf import settings @@ -62,6 +63,8 @@ from ishtar_common.utils import ( get_generated_id, ) +logger = logging.getLogger(__name__) + class DivisionContainer(DashboardFormItem): DIVISION_TEMPLATE = """ bool: + """ + Update weight in db if changed. + :return: True if changed + """ + if not self.pk: + return False + if self.calculated_weight != self._calculate_weight(): + Container.objects.filter(pk=self.pk).update(calculated_weight=self.calculated_weight) + return True + return False + + def _calculate_weight(self) -> bool: """ Calculate the weight of the contained finds + tare weight of the @@ -1669,108 +1699,126 @@ class Container( return self.set_localisation(0, value) set_localisation_1.post_save = True + set_localisation_1._no_repost_save = True @post_importer_action def set_localisation_2(self, context, value): return self.set_localisation(1, value) set_localisation_2.post_save = True + set_localisation_2._no_repost_save = True @post_importer_action def set_localisation_3(self, context, value): return self.set_localisation(2, value) set_localisation_3.post_save = True + set_localisation_3._no_repost_save = True @post_importer_action def set_localisation_4(self, context, value): return self.set_localisation(3, value) set_localisation_4.post_save = True + set_localisation_4._no_repost_save = True @post_importer_action def set_localisation_5(self, context, value): return self.set_localisation(4, value) set_localisation_5.post_save = True + set_localisation_5._no_repost_save = True @post_importer_action def set_localisation_6(self, context, value): return self.set_localisation(5, value) set_localisation_6.post_save = True + set_localisation_6._no_repost_save = True @post_importer_action def set_localisation_7(self, context, value): return self.set_localisation(6, value) set_localisation_7.post_save = True + set_localisation_7._no_repost_save = True @post_importer_action def set_localisation_8(self, context, value): return self.set_localisation(7, value) set_localisation_8.post_save = True + set_localisation_8._no_repost_save = True @post_importer_action def set_localisation_9(self, context, value): return self.set_localisation(8, value) set_localisation_9.post_save = True + set_localisation_9._no_repost_save = True @post_importer_action def set_static_localisation_1(self, context, value): return self.set_static_localisation(0, value) set_static_localisation_1.post_save = True + set_static_localisation_1._no_repost_save = True @post_importer_action def set_static_localisation_2(self, context, value): return self.set_static_localisation(1, value) set_static_localisation_2.post_save = True + set_static_localisation_2._no_repost_save = True @post_importer_action def set_static_localisation_3(self, context, value): return self.set_static_localisation(2, value) set_static_localisation_3.post_save = True + set_static_localisation_3._no_repost_save = True @post_importer_action def set_static_localisation_4(self, context, value): return self.set_static_localisation(3, value) set_static_localisation_4.post_save = True + set_static_localisation_4._no_repost_save = True @post_importer_action def set_static_localisation_5(self, context, value): return self.set_static_localisation(4, value) set_static_localisation_5.post_save = True + set_static_localisation_5._no_repost_save = True @post_importer_action def set_static_localisation_6(self, context, value): return self.set_static_localisation(5, value) set_static_localisation_6.post_save = True + set_static_localisation_6._no_repost_save = True @post_importer_action def set_static_localisation_7(self, context, value): return self.set_static_localisation(6, value) set_static_localisation_7.post_save = True + set_static_localisation_7._no_repost_save = True @post_importer_action def set_static_localisation_8(self, context, value): return self.set_static_localisation(7, value) set_static_localisation_8.post_save = True + set_static_localisation_8._no_repost_save = True @post_importer_action def set_static_localisation_9(self, context, value): return self.set_static_localisation(8, value) set_static_localisation_9.post_save = True + set_static_localisation_9._no_repost_save = True DOC_VALUES = [ ( @@ -1930,6 +1978,8 @@ class Container( return ((self.__class__, q.values_list("id", flat=True)),) def save(self, *args, **kwargs): + if self.pk: + logger.debug(f"[ishtar] archaeological_warehouse.models.Container.save - {self.pk} - {self.cached_label}") self.pre_save() super().save(*args, **kwargs) self._change_child_location(self) -- cgit v1.2.3