summaryrefslogtreecommitdiff
path: root/archaeological_finds/models_finds.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2024-09-09 14:45:17 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2024-09-10 15:40:21 +0200
commit66232651ef2a2c1f331dc381a8f86f24a279ba85 (patch)
treee4c43e6209a35d84f3b1b362237570224f511fd5 /archaeological_finds/models_finds.py
parent39daa533e0b9d2a942223eeca817cdaa8887d69b (diff)
downloadIshtar-66232651ef2a2c1f331dc381a8f86f24a279ba85.tar.bz2
Ishtar-66232651ef2a2c1f331dc381a8f86f24a279ba85.zip
✨ find container history: manage first packaging info
Diffstat (limited to 'archaeological_finds/models_finds.py')
-rw-r--r--archaeological_finds/models_finds.py74
1 files changed, 73 insertions, 1 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 55219d452..f8a978b67 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -2050,6 +2050,10 @@ class Find(
related_name="finds",
on_delete=models.SET_NULL,
)
+ container_fisrt_full_location = models.TextField(
+ _("Container - first full location"), default="", blank=True,
+ help_text=_("Updated as long as no packaging is attached")
+ )
container_ref = models.ForeignKey(
"archaeological_warehouse.Container",
verbose_name=_("Reference container"),
@@ -2058,6 +2062,10 @@ class Find(
related_name="finds_ref",
on_delete=models.SET_NULL,
)
+ container_ref_fisrt_full_location = models.TextField(
+ _("Reference container - first full location"), default="", blank=True,
+ help_text=_("Updated as long as no packaging is attached")
+ )
is_complete = models.NullBooleanField(_("Is complete?"), blank=True, null=True)
object_types = models.ManyToManyField(
ObjectType, verbose_name=_("Object types"), related_name="find", blank=True
@@ -2389,6 +2397,14 @@ class Find(
def show_url(self):
return reverse("show-find", args=[self.pk, ""])
+ @property
+ def has_packaging_for_current_container(self):
+ return FindTreatment.objects.filter(find=self, location_type__in=["B", "C"])
+
+ @property
+ def has_packaging_for_reference_container(self):
+ return FindTreatment.objects.filter(find=self, location_type__in=["B", "R"])
+
def public_representation(self):
dct = super(Find, self).public_representation()
dct.update(
@@ -3341,6 +3357,53 @@ class Find(
set_static_localisation_9.post_save = True
+ def update_current_full_location(self, full_location=None):
+ """
+ If relevant update full location of current container
+ :param full_location: provided if update is triggered from container
+ """
+ if getattr(self, "_container_fisrt_full_location", False) \
+ or self.has_packaging_for_current_container:
+ return False
+ self._container_fisrt_full_location = True
+ if self.container:
+ if not full_location:
+ full_location = self.container.generate_full_location()
+ if full_location == self.container_fisrt_full_location:
+ return False
+ self.container_fisrt_full_location = full_location
+ else:
+ if self.container_fisrt_full_location == "":
+ return False
+ self.container_fisrt_full_location = ""
+ return True
+
+ def update_ref_full_location(self, full_location=None):
+ """
+ If relevant update full location of reference container
+ :param full_location: provided if update is triggered from container
+ """
+ if getattr(self, "_container_ref_fisrt_full_location", False) \
+ or self.has_packaging_for_reference_container:
+ return False
+ self._container_ref_fisrt_full_location = True
+ if self.container_ref:
+ if not full_location:
+ full_location = self.container_ref.generate_full_location()
+ if full_location == self.container_ref_fisrt_full_location:
+ return False
+ self.container_ref_fisrt_full_location = full_location
+ else:
+ if self.container_ref_fisrt_full_location == "":
+ return False
+ self.container_ref_fisrt_full_location = ""
+ return True
+
+ def update_full_location(self):
+ updated = self.update_current_full_location()
+ updated |= self.update_ref_full_location()
+ return updated
+
def generate_index(self):
"""
Generate index based on operation or context record (based on
@@ -3402,6 +3465,10 @@ class Find(
except Container.DoesNotExist:
pass
+ if self.update_full_location():
+ self.save()
+ return True
+
updated = self.update_external_id(save=False)
if updated:
self._cached_label_checked = False
@@ -3557,9 +3624,11 @@ for attr in Find.HISTORICAL_M2M:
LOCATION_TYPE = [
["C", _("Current")],
["R", _("Reference")],
- ["B", _("Both")],
+ ["B", _("Reference/current")],
]
+LOCATION_TYPE_DICT = dict(LOCATION_TYPE)
+
class FindTreatment(models.Model):
"""
@@ -3584,6 +3653,9 @@ class FindTreatment(models.Model):
verbose_name_plural = _("Find - Treatments")
db_table = 'archaeological_finds_find_treatments'
+ def location_type_label(self):
+ return LOCATION_TYPE_DICT[self.location_type]
+
def generate_full_location(self):
if getattr(self, "_full_location_set", False) or self.full_location or (
not self.treatment.is_current_container_changer and