diff options
Diffstat (limited to 'archaeological_finds')
| -rw-r--r-- | archaeological_finds/models_finds.py | 22 | ||||
| -rw-r--r-- | archaeological_finds/models_treatments.py | 17 | ||||
| -rw-r--r-- | archaeological_finds/tests.py | 2 |
3 files changed, 33 insertions, 8 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 0d7ee8b71..4b7536735 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -2428,11 +2428,11 @@ class Find( @property def has_packaging_for_current_container(self): - return FindTreatment.objects.filter(find=self, location_type__in=["B", "C"]) + return FindTreatment.objects.filter(find=self, location_type__in=["B", "C"]).exists() @property def has_packaging_for_reference_container(self): - return FindTreatment.objects.filter(find=self, location_type__in=["B", "R"]) + return FindTreatment.objects.filter(find=self, location_type__in=["B", "R"]).exists() def public_representation(self): dct = super(Find, self).public_representation() @@ -3404,8 +3404,10 @@ class Find( :param full_location: provided if update is triggered from container """ if getattr(self, "_container_fisrt_full_location", False) \ + or not self.pk \ or self.has_packaging_for_current_container: return False + self._container_fisrt_full_location = True if self.container: if not full_location: @@ -3421,6 +3423,9 @@ class Find( if return_value: return "" self.container_fisrt_full_location = "" + Find.objects.filter(pk=self.pk).update( + container_fisrt_full_location=self.container_fisrt_full_location + ) return True def update_ref_full_location(self, full_location=None, return_value=False): @@ -3429,8 +3434,11 @@ class Find( :param full_location: provided if update is triggered from container """ if getattr(self, "_container_ref_fisrt_full_location", False) \ + or not self.pk \ + or self.has_packaging_for_current_container \ or self.has_packaging_for_reference_container: return False + # if current container has already changed - do not change first self._container_ref_fisrt_full_location = True if self.container_ref: if not full_location: @@ -3446,6 +3454,9 @@ class Find( if return_value: return "" self.container_ref_fisrt_full_location = "" + Find.objects.filter(pk=self.pk).update( + container_ref_fisrt_full_location=self.container_ref_fisrt_full_location + ) return True def update_full_location(self): @@ -3514,9 +3525,7 @@ class Find( except Container.DoesNotExist: pass - if self.update_full_location(): - self.save() - return True + self.update_full_location() updated = self.update_external_id(save=False) if updated: @@ -3694,7 +3703,8 @@ class FindTreatment(models.Model): on_delete=models.CASCADE ) full_location = models.TextField(_("Full location"), default="", blank=True) - location_type = models.CharField(_("Location type"), max_length=1, choices=LOCATION_TYPE, + location_type = models.CharField(_("Location type"), max_length=1, + choices=LOCATION_TYPE, default="C") class Meta: diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py index 429c9c3f3..24010984f 100644 --- a/archaeological_finds/models_treatments.py +++ b/archaeological_finds/models_treatments.py @@ -819,6 +819,23 @@ class Treatment( post_save.connect(cached_label_changed, sender=Treatment) +def treatment_attached_changed(sender, **kwargs): + # force full location + instance = kwargs.get("instance", None) + find_pk_set = kwargs.get("pk_set", None) + if not find_pk_set or not instance: + return + for find_id in find_pk_set: + q = FindTreatment.objects.filter(find_id=find_id, treatment_id=instance.pk) + if not q.count(): + continue + for ft in q.all(): + ft.generate_full_location() + + +m2m_changed.connect(treatment_attached_changed, sender=Treatment.finds.through) + + def pre_delete_treatment(sender, **kwargs): treatment = kwargs.get("instance") for find in Find.objects.filter(upstream_treatment=treatment).all(): diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py index e84d86836..889742ba2 100644 --- a/archaeological_finds/tests.py +++ b/archaeological_finds/tests.py @@ -2308,8 +2308,6 @@ class FindQATest(FindInit, TestCase): value = check[k] value2 = check[k] if k == "container" and data["qa-packaging-container_to_change"] == "reference": - # if current not set -> auto set container to container_ref - value = check["container_ref"] # current set for find_1 -> keep it value2 = Container.objects.get(reference="Test2 base") if k == "container_ref" and data["qa-packaging-container_to_change"] == "current": |
