diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2026-01-22 11:24:52 +0100 |
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2026-03-10 11:11:46 +0100 |
| commit | 5311aea5f9b9bd0fbfb12e368560ddd5d150162b (patch) | |
| tree | 4a4050af45b81a1de8b1a32b3f34016bf3499bb2 /archaeological_finds/models_finds.py | |
| parent | ec65aff80a94fce6f74c4f89673abc579cc53310 (diff) | |
| download | Ishtar-5311aea5f9b9bd0fbfb12e368560ddd5d150162b.tar.bz2 Ishtar-5311aea5f9b9bd0fbfb12e368560ddd5d150162b.zip | |
🚧 Statement condition: models
Diffstat (limited to 'archaeological_finds/models_finds.py')
| -rw-r--r-- | archaeological_finds/models_finds.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index f1144a09a..9e9886635 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -180,6 +180,11 @@ class TreatmentType(HierarchicalType): "current location." ), ) + is_statement_condition = models.BooleanField( + _("Related to statement condition"), + default=False, + help_text=_("Available as a treatment for statement condition."), + ) class Meta: verbose_name = _("Treatment type") @@ -2419,6 +2424,7 @@ class Find( verbose_name=_("Recommended treatments"), related_name="old_finds_recommended", blank=True, + help_text=_("Deprecated") ) recommended_treatments = models.ManyToManyField( RecommendedTreatmentType, @@ -2597,6 +2603,42 @@ class Find( return reverse("show-find", args=[self.pk, ""]) @property + def statement_conditions_list(self): + if not self.statement_conditions.exists(): + return [] + # get all diff from previous states + StatementCondition = apps.get_model("archaeological_finds", "StatementCondition") + statement_conditions_list = list( + self.statement_conditions.filter(initial=False).order_by("pk").all()) + q = self.statement_conditions.order_by("-pk").filter(initial=True) + if q.exists(): + previous = q.all()[0] + else: # if no initial is set get diff from the find + previous = self + for state in statement_conditions_list: + diff = {} + for field in StatementCondition._meta.get_fields(): + attr = field.name + if attr in StatementCondition.OVERLOADED_FIELDS: + previous_value = getattr(previous, attr) or None + value = getattr(state, attr) or None + if previous_value != value: + if value is None or value == "": + value = "-" + diff[field.verbose_name] = value + elif attr in StatementCondition.OVERLOADED_M2M_FIELDS: + previous_value = [str(v) for v in getattr(previous, attr).all()] + value = [str(v) for v in list(getattr(state, attr).all())] + if previous_value != value: + if value: + diff[field.verbose_name] = " ; ".join(value) + else: + diff[field.verbose_name] = "-" + state.diff = diff + previous = state + return list(reversed(statement_conditions_list)) + + @property def has_packaging_for_current_container(self): return FindTreatment.objects.filter(find=self, location_type__in=["B", "C"]).exists() |
