summaryrefslogtreecommitdiff
path: root/archaeological_warehouse
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_warehouse')
-rw-r--r--archaeological_warehouse/models.py52
1 files changed, 51 insertions, 1 deletions
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 = """<a class="display_details"
@@ -323,7 +326,6 @@ class Warehouse(
),
}
GEO_LABEL = "name"
- FORCE_CASCADE_UPDATE = True
CACHED_LABELS = ["cached_town_label"]
QA_EDIT = QuickAction(
@@ -465,6 +467,7 @@ class Warehouse(
self.skip_history_when_saving = True
self._no_move = True
self.save()
+ return changed
def get_container_type_by_place(self, place: int):
"""
@@ -659,6 +662,19 @@ class Warehouse(
return self.town
return ""
+ def check_cascade_update(self):
+ # arbitrary check if a "location" or a "responsibility" container are impacted by a change
+ # arbitrary because check every formula is not efficient
+ q1 = Container.objects.filter(location=self)
+ q2 = Container.objects.exclude(location=self).filter(responsibility=self)
+ for q in (q1, q2):
+ if q.count():
+ container = q.all()[0]
+ if (container._generate_cached_label() != container.cached_label) or (
+ container._generate_cached_location() != container.cached_location):
+ return True
+ return False
+
def save(self, *args, **kwargs):
self.update_search_vector()
super(Warehouse, self).save(*args, **kwargs)
@@ -1243,6 +1259,7 @@ class Container(
self.skip_history_when_saving = True
self._no_move = True
self.save()
+ return changed
@property
def start_division_number(self):
@@ -1328,6 +1345,19 @@ class Container(
def _generate_cached_weight(self):
return self.weight if self.weight else self.calculated_weight
+ def update_weight(self) -> 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)