diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-11-13 18:55:30 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-11-14 16:57:37 +0100 | 
| commit | d0d146cc099bfe2d58a8c8ec6e57096661d1fdcb (patch) | |
| tree | 1007a19ed094bb463a9234909d84412a379a3c9c /archaeological_operations/models.py | |
| parent | 1d1fd6c794c8ca8e758fc416b43e0f881136057f (diff) | |
| download | Ishtar-d0d146cc099bfe2d58a8c8ec6e57096661d1fdcb.tar.bz2 Ishtar-d0d146cc099bfe2d58a8c8ec6e57096661d1fdcb.zip | |
⚡️ improve parcel post-treatments - add timestamp to prevent multiple geo and cached_label edition
Diffstat (limited to 'archaeological_operations/models.py')
| -rw-r--r-- | archaeological_operations/models.py | 45 | 
1 files changed, 35 insertions, 10 deletions
| diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 4f0112710..3ebf98349 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -1113,10 +1113,10 @@ class Operation(          "scientist": {("person_types", PersonType): ("head_scientist", "sra_agent")},      }      CACHED_LABELS = [ -        "cached_label",          "cached_towns_label",          "cached_periods",          "cached_remains", +        "cached_label",      ]      objects = UUIDModelManager() @@ -1296,7 +1296,7 @@ class Operation(          "towns__numero_insee__startswith": "_get_department_code",      } -    DOWN_MODEL_UPDATE = ["context_record"] +    DOWN_MODEL_UPDATE = ["parcels", "context_record"]      HISTORICAL_M2M = [          "remains", @@ -1532,6 +1532,12 @@ class Operation(          related_name="minutes_writer",          on_delete=models.SET_NULL,      ) +    cached_label = models.TextField( +        _("Cached label"), +        blank=True, +        default="", +        help_text=_("Generated automatically - do not edit"), +    )      cached_towns_label = models.TextField(          _("Cached town label"),          blank=True, @@ -1676,6 +1682,10 @@ class Operation(          return self.code_patriarche      @property +    def auto_external_id(self): +        return False + +    @property      def short_label(self):          if settings.COUNTRY == "fr":              return self.reference @@ -1697,7 +1707,7 @@ class Operation(          return [town.label_with_areas for town in self.towns.all()]      def towns_label(self): -        return " ; ".join(self.towns_codes()) +        return " ; ".join([town.name for town in self.towns.all()])      def has_finds(self):          from archaeological_finds.models import BaseFind @@ -1762,7 +1772,7 @@ class Operation(          return cached_label      def _generate_cached_towns_label(self): -        return self.towns_label() or "-" +        return self.towns_label() or _("No associated town")      def _generate_cached_remains(self):          return " & ".join([str(remain) for remain in self.remains.all()]) or "-" @@ -1773,10 +1783,6 @@ class Operation(      def _get_associated_cached_labels(self):          return list(self.context_record.all()) -    def _cached_labels_bulk_update(self): -        self.context_record.model.cached_label_bulk_update(operation_id=self.pk) -        return True -      def _get_base_image_path(self):          return "{}/{}/{}".format(self.SLUG, self.year, self.reference) @@ -3304,8 +3310,27 @@ def parcel_post_save(sender, **kwargs):          parcel.save()          return -    if parcel.context_record.count(): -        parcel.context_record.model.cached_label_bulk_update(parcel_id=parcel.id) +    cr_external_id_formula = get_current_profile().context_record_external_id +    has_ext_id = "{parcel__external_id}" in cr_external_id_formula +    has_nb = "{parcel__parcel_number}" in cr_external_id_formula +    has_section = "{parcel__section}" in cr_external_id_formula + +    q = parcel.context_record +    if q.count(): +        # check if first context record is affected +        cr = q.all()[0] +        need_update = not has_nb and not has_section and not has_ext_id  # cannot check easily +        if has_ext_id: +            need_update += parcel.external_id not in cr.external_id +        if has_section and parcel.section: +            need_update += parcel.section not in cr.external_id +        if has_nb and parcel.parcel_number: +            need_update += parcel.parcel_number not in cr.external_id +        if need_update: +            for cr in q.all(): +                cr.no_post_process() +                cr._cached_label_checked = False +                cr.save()      if (          parcel.operation | 
