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 | |
| 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')
| -rw-r--r-- | archaeological_operations/migrations/0113_auto_20231114_1058.py | 103 | ||||
| -rw-r--r-- | archaeological_operations/models.py | 45 | ||||
| -rw-r--r-- | archaeological_operations/tests.py | 9 | 
3 files changed, 143 insertions, 14 deletions
diff --git a/archaeological_operations/migrations/0113_auto_20231114_1058.py b/archaeological_operations/migrations/0113_auto_20231114_1058.py new file mode 100644 index 000000000..3b1bb0c55 --- /dev/null +++ b/archaeological_operations/migrations/0113_auto_20231114_1058.py @@ -0,0 +1,103 @@ +# Generated by Django 2.2.24 on 2023-11-14 10:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + +    dependencies = [ +        ('archaeological_operations', '0112_migrate_created'), +    ] + +    operations = [ +        migrations.AddField( +            model_name='administrativeact', +            name='timestamp_geo', +            field=models.IntegerField(blank=True, null=True, verbose_name='Timestamp geo'), +        ), +        migrations.AddField( +            model_name='administrativeact', +            name='timestamp_label', +            field=models.IntegerField(blank=True, null=True, verbose_name='Timestamp label'), +        ), +        migrations.AddField( +            model_name='archaeologicalsite', +            name='timestamp_geo', +            field=models.IntegerField(blank=True, null=True, verbose_name='Timestamp geo'), +        ), +        migrations.AddField( +            model_name='archaeologicalsite', +            name='timestamp_label', +            field=models.IntegerField(blank=True, null=True, verbose_name='Timestamp label'), +        ), +        migrations.AddField( +            model_name='historicaladministrativeact', +            name='timestamp_geo', +            field=models.IntegerField(blank=True, null=True, verbose_name='Timestamp geo'), +        ), +        migrations.AddField( +            model_name='historicaladministrativeact', +            name='timestamp_label', +            field=models.IntegerField(blank=True, null=True, verbose_name='Timestamp label'), +        ), +        migrations.AddField( +            model_name='historicalarchaeologicalsite', +            name='timestamp_geo', +            field=models.IntegerField(blank=True, null=True, verbose_name='Timestamp geo'), +        ), +        migrations.AddField( +            model_name='historicalarchaeologicalsite', +            name='timestamp_label', +            field=models.IntegerField(blank=True, null=True, verbose_name='Timestamp label'), +        ), +        migrations.AddField( +            model_name='historicaloperation', +            name='timestamp_geo', +            field=models.IntegerField(blank=True, null=True, verbose_name='Timestamp geo'), +        ), +        migrations.AddField( +            model_name='historicaloperation', +            name='timestamp_label', +            field=models.IntegerField(blank=True, null=True, verbose_name='Timestamp label'), +        ), +        migrations.AddField( +            model_name='operation', +            name='timestamp_geo', +            field=models.IntegerField(blank=True, null=True, verbose_name='Timestamp geo'), +        ), +        migrations.AddField( +            model_name='operation', +            name='timestamp_label', +            field=models.IntegerField(blank=True, null=True, verbose_name='Timestamp label'), +        ), +        migrations.AddField( +            model_name='parcel', +            name='timestamp_geo', +            field=models.IntegerField(blank=True, null=True, verbose_name='Timestamp geo'), +        ), +        migrations.AddField( +            model_name='parcel', +            name='timestamp_label', +            field=models.IntegerField(blank=True, null=True, verbose_name='Timestamp label'), +        ), +        migrations.AddField( +            model_name='parcelowner', +            name='timestamp_geo', +            field=models.IntegerField(blank=True, null=True, verbose_name='Timestamp geo'), +        ), +        migrations.AddField( +            model_name='parcelowner', +            name='timestamp_label', +            field=models.IntegerField(blank=True, null=True, verbose_name='Timestamp label'), +        ), +        migrations.AlterField( +            model_name='historicaloperation', +            name='cached_label', +            field=models.TextField(blank=True, default='', help_text='Generated automatically - do not edit', verbose_name='Cached label'), +        ), +        migrations.AlterField( +            model_name='operation', +            name='cached_label', +            field=models.TextField(blank=True, default='', help_text='Generated automatically - do not edit', verbose_name='Cached label'), +        ), +    ] 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 diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 1c2623389..331c24659 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -2153,16 +2153,17 @@ class OperationTest(TestCase, OperationInitTest):          operation = self.operations[0]          self.assertIsNotNone(operation.cached_label)          town, ope_id = operation.cached_label.split(" | ") -        self.assertIn(town, ("Intercommunal", "Multi-town")) -        self.assertEqual(ope_id, "OA1 - OP2010-1") +        self.assertIn(town, ("Pas de commune associée", "No associated town")) +        self.assertEqual(ope_id, "OA1")          operation = models.Operation.objects.get(pk=operation.pk)          operation.year = 2011 +        operation.code_patriarche = ""          operation.save()          operation.towns.add(self.towns[0])          operation = models.Operation.objects.get(pk=operation.pk)          self.assertIsNotNone(operation.cached_label)          town, ope_id = operation.cached_label.split(" | ") -        self.assertEqual(ope_id, "OA1 - OP2011-1") +        self.assertEqual(ope_id, "OP2011-1")          self.assertEqual(town, self.towns[0].name)      def test_search_vector_update(self): @@ -3834,7 +3835,7 @@ class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase):              operation = models.Operation.objects.get(pk=test_object.operations[0].pk)              town_str = town_2.name              test_object.assertEqual( -                operation.complete_identifier[:len(town_str)], town_str +                operation.cached_label[:len(town_str)], town_str              )          self.form_datas[0].extra_tests = [post_first_wizard]  | 
