diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-10-24 15:05:28 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-10-27 12:42:53 +0100 | 
| commit | c682a67e79d4a2f47ff97940c377aeb4fcc4ad05 (patch) | |
| tree | 7c17d41ff47d0ec8d3061f42e37d8e0d29d8a8a2 | |
| parent | e6fc3223057ff1c79ad15f2f14d66dc195cffacd (diff) | |
| download | Ishtar-c682a67e79d4a2f47ff97940c377aeb4fcc4ad05.tar.bz2 Ishtar-c682a67e79d4a2f47ff97940c377aeb4fcc4ad05.zip  | |
🐛 ✨ person, organization tables: fix and optimize town name and person type list (refs #6441)
17 files changed, 208 insertions, 36 deletions
diff --git a/archaeological_context_records/migrations/0123_add_timezone_django_v4.py b/archaeological_context_records/migrations/0123_add_timezone_django_v4.py index 0d141f14a..5e9bf1249 100644 --- a/archaeological_context_records/migrations/0123_add_timezone_django_v4.py +++ b/archaeological_context_records/migrations/0123_add_timezone_django_v4.py @@ -10,7 +10,7 @@ import re  class Migration(migrations.Migration):      dependencies = [ -        ('ishtar_common', '0265_add_timezone_django_v4'), +        ('ishtar_common', '0267_add_timezone_django_v4'),          ('archaeological_context_records', '0122_cr_ishtar_users'),      ] diff --git a/archaeological_files/migrations/0120_add_timezone_django_v4.py b/archaeological_files/migrations/0120_add_timezone_django_v4.py index 128d135bd..910efb28b 100644 --- a/archaeological_files/migrations/0120_add_timezone_django_v4.py +++ b/archaeological_files/migrations/0120_add_timezone_django_v4.py @@ -9,7 +9,7 @@ import re  class Migration(migrations.Migration):      dependencies = [ -        ('ishtar_common', '0265_add_timezone_django_v4'), +        ('ishtar_common', '0267_add_timezone_django_v4'),          ('archaeological_files', '0119_file_ishtar_users'),      ] diff --git a/archaeological_finds/migrations/0142_add_timezone_django_v4.py b/archaeological_finds/migrations/0142_add_timezone_django_v4.py index d7ab6dcd8..2a59695f1 100644 --- a/archaeological_finds/migrations/0142_add_timezone_django_v4.py +++ b/archaeological_finds/migrations/0142_add_timezone_django_v4.py @@ -11,7 +11,7 @@ import re  class Migration(migrations.Migration):      dependencies = [ -        ('ishtar_common', '0265_add_timezone_django_v4'), +        ('ishtar_common', '0267_add_timezone_django_v4'),          ('archaeological_finds', '0141_data_migration_recommanded_treatments'),      ] diff --git a/archaeological_operations/migrations/0123_add_timezone_django_v4.py b/archaeological_operations/migrations/0123_add_timezone_django_v4.py index 6d581569b..3c60ba456 100644 --- a/archaeological_operations/migrations/0123_add_timezone_django_v4.py +++ b/archaeological_operations/migrations/0123_add_timezone_django_v4.py @@ -10,7 +10,7 @@ import re  class Migration(migrations.Migration):      dependencies = [ -        ('ishtar_common', '0265_add_timezone_django_v4'), +        ('ishtar_common', '0267_add_timezone_django_v4'),          ('archaeological_operations', '0122_admin_act_many_intented_to'),      ] diff --git a/archaeological_warehouse/migrations/0124_warehouse_cached_town.py b/archaeological_warehouse/migrations/0124_warehouse_cached_town.py new file mode 100644 index 000000000..669bcd3af --- /dev/null +++ b/archaeological_warehouse/migrations/0124_warehouse_cached_town.py @@ -0,0 +1,31 @@ +# Generated by Django 2.2.24 on 2025-10-24 15:21 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + +    dependencies = [ +        ('archaeological_warehouse', '0123_warehouse_container_ishtar_users'), +    ] + +    operations = [ +        migrations.AddField( +            model_name='historicalwarehouse', +            name='cached_town', +            field=models.TextField(blank=True, default='', verbose_name='Cached town'), +        ), +        migrations.AddField( +            model_name='warehouse', +            name='cached_town', +            field=models.TextField(blank=True, default='', verbose_name='Cached town'), +        ), +        migrations.RemoveField( +            model_name='historicalwarehouse', +            name='cached_town_label', +        ), +        migrations.RemoveField( +            model_name='warehouse', +            name='cached_town_label', +        ), +    ] diff --git a/archaeological_warehouse/migrations/0125_migrate_cached_town.py b/archaeological_warehouse/migrations/0125_migrate_cached_town.py new file mode 100644 index 000000000..49f914185 --- /dev/null +++ b/archaeological_warehouse/migrations/0125_migrate_cached_town.py @@ -0,0 +1,29 @@ +# Generated by Django 2.2.24 on 2025-10-24 12:59 + +from django.db import migrations + + +def _generate_cached_town(Town, town): +    if town.precise_town_id: +        return Town.objects.get(id=town.precise_town_id).name +    return town.town or "" + + +def migrate_cached_towns(apps, __): +    Town = apps.get_model("ishtar_common", "Town") +    Warehouse = apps.get_model("archaeological_warehouse", "Warehouse") +    for warehouse in Warehouse.objects.all(): +        Warehouse.objects.filter(pk=warehouse.pk).update( +            cached_town=_generate_cached_town(Town, warehouse), +        ) + + +class Migration(migrations.Migration): + +    dependencies = [ +        ('archaeological_warehouse', '0124_warehouse_cached_town'), +    ] + +    operations = [ +        migrations.RunPython(migrate_cached_towns) +    ] diff --git a/archaeological_warehouse/migrations/0124_add_timezone_django_v4.py b/archaeological_warehouse/migrations/0126_add_timezone_django_v4.py index 356140e11..41cda4e35 100644 --- a/archaeological_warehouse/migrations/0124_add_timezone_django_v4.py +++ b/archaeological_warehouse/migrations/0126_add_timezone_django_v4.py @@ -10,8 +10,8 @@ import re  class Migration(migrations.Migration):      dependencies = [ -        ('ishtar_common', '0265_add_timezone_django_v4'), -        ('archaeological_warehouse', '0123_warehouse_container_ishtar_users'), +        ('ishtar_common', '0267_add_timezone_django_v4'), +        ('archaeological_warehouse', '0125_migrate_cached_town'),      ]      operations = [ diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index bc3015b93..9c465ebf1 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -294,10 +294,10 @@ class Warehouse(      SHOW_URL = "show-warehouse"      DELETE_URL = "delete-warehouse"      DOWN_MODEL_UPDATE = ["containers", "responsibilities"] -    TABLE_COLS = ["name", "warehouse_type__label", "cached_town_label"] +    TABLE_COLS = ["name", "warehouse_type__label", "cached_town"]      COL_LABELS = {          "warehouse_type__label": _("Type"), -        "cached_town_label": _("Town"), +        "cached_town": _("Town"),      }      INITIAL_VALUES = ["name", "slug"]      NEW_QUERY_ENGINE = True @@ -340,7 +340,7 @@ class Warehouse(      DEFAULT_SEARCH_FORM = ("archaeological_warehouse.forms", "WarehouseSelect")      GEO_LABEL = "name" -    CACHED_LABELS = ["cached_town_label"] +    CACHED_LABELS = ["cached_town"]      QA_EDIT = QuickAction(          url="warehouse-qa-bulk-update", @@ -433,12 +433,6 @@ class Warehouse(          default=0,          help_text=_("Automatically generated"),      ) -    cached_town_label = models.TextField( -        _("Cached town label"), -        blank=True, -        default="", -        help_text=_("Generated automatically - do not edit"), -    )      SUB_ADDRESSES = ["organization", "person_in_charge"]      class Meta: @@ -650,13 +644,6 @@ class Warehouse(              wdiv.delete()          merge_model_objects(self, item, keep_old=keep_old) -    def _generate_cached_town_label(self): -        if self.precise_town: -            return str(self.precise_town) -        if self.town: -            return self.town -        return "" -      def check_cascade_update(self):          # arbitrary check if a "location" or a "responsibility" container are impacted by a change          # arbitrary because check every formula is not efficient diff --git a/ishtar_common/migrations/0265_cached_town.py b/ishtar_common/migrations/0265_cached_town.py new file mode 100644 index 000000000..01f392e78 --- /dev/null +++ b/ishtar_common/migrations/0265_cached_town.py @@ -0,0 +1,53 @@ +# Generated by Django 2.2.24 on 2025-10-24 12:39 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + +    dependencies = [ +        ('ishtar_common', '0264_source_type_add_order'), +    ] + +    operations = [ +        migrations.AddField( +            model_name='historicalorganization', +            name='cached_town', +            field=models.TextField(blank=True, default='', verbose_name='Cached town'), +        ), +        migrations.AddField( +            model_name='historicalperson', +            name='cached_person_types', +            field=models.TextField(blank=True, default='', verbose_name='Cached person types'), +        ), +        migrations.AddField( +            model_name='historicalperson', +            name='cached_town', +            field=models.TextField(blank=True, default='', verbose_name='Cached town'), +        ), +        migrations.AddField( +            model_name='organization', +            name='cached_town', +            field=models.TextField(blank=True, default='', verbose_name='Cached town'), +        ), +        migrations.AddField( +            model_name='person', +            name='cached_person_types', +            field=models.TextField(blank=True, default='', verbose_name='Cached person types'), +        ), +        migrations.AddField( +            model_name='person', +            name='cached_town', +            field=models.TextField(blank=True, default='', verbose_name='Cached town'), +        ), +        migrations.AddField( +            model_name='historicalperson', +            name='cached_profiles', +            field=models.TextField(blank=True, default='', verbose_name='Cached profiles'), +        ), +        migrations.AddField( +            model_name='person', +            name='cached_profiles', +            field=models.TextField(blank=True, default='', verbose_name='Cached profiles'), +        ), +    ] diff --git a/ishtar_common/migrations/0266_migrate_cached_town.py b/ishtar_common/migrations/0266_migrate_cached_town.py new file mode 100644 index 000000000..e5904a5c5 --- /dev/null +++ b/ishtar_common/migrations/0266_migrate_cached_town.py @@ -0,0 +1,37 @@ +# Generated by Django 2.2.24 on 2025-10-24 12:59 + +from django.db import migrations + + +def _generate_cached_town(Town, town): +    if town.precise_town_id: +        return Town.objects.get(id=town.precise_town_id).name +    return town.town or "" + + +def migrate_cached_towns(apps, __): +    Town = apps.get_model("ishtar_common", "Town") +    Person = apps.get_model("ishtar_common", "Person") +    for person in Person.objects.all(): +        Person.objects.filter(pk=person.pk).update( +            cached_town=_generate_cached_town(Town, person), +            cached_person_types=", ".join(pt.label for pt in person.person_types.all()), +            cached_profiles=", ".join(set([p.profile_type.label +                                           for p in person.profiles.all()])) +        ) +    Organization = apps.get_model("ishtar_common", "Organization") +    for organization in Organization.objects.all(): +        Organization.objects.filter(pk=organization.pk).update( +            cached_town=_generate_cached_town(Town, organization), +        ) + + +class Migration(migrations.Migration): + +    dependencies = [ +        ('ishtar_common', '0265_cached_town'), +    ] + +    operations = [ +        migrations.RunPython(migrate_cached_towns) +    ] diff --git a/ishtar_common/migrations/0265_add_timezone_django_v4.py b/ishtar_common/migrations/0267_add_timezone_django_v4.py index ea4e0c595..0eb973d87 100644 --- a/ishtar_common/migrations/0265_add_timezone_django_v4.py +++ b/ishtar_common/migrations/0267_add_timezone_django_v4.py @@ -10,7 +10,7 @@ import re  class Migration(migrations.Migration):      dependencies = [ -        ('ishtar_common', '0264_source_type_add_order'), +        ('ishtar_common', '0266_migrate_cached_town'),      ]      operations = [ diff --git a/ishtar_common/migrations/0266_userrequesttoken_usertoken.py b/ishtar_common/migrations/0268_userrequesttoken_usertoken.py index 1ff39d163..9c13acc64 100644 --- a/ishtar_common/migrations/0266_userrequesttoken_usertoken.py +++ b/ishtar_common/migrations/0268_userrequesttoken_usertoken.py @@ -10,7 +10,7 @@ class Migration(migrations.Migration):      dependencies = [          ('auth', '0012_alter_user_first_name_max_length'),          migrations.swappable_dependency(settings.AUTH_USER_MODEL), -        ('ishtar_common', '0265_add_timezone_django_v4'), +        ('ishtar_common', '0267_add_timezone_django_v4'),      ]      operations = [ diff --git a/ishtar_common/migrations/0267_gis_importchunk.py b/ishtar_common/migrations/0269_gis_importchunk.py index 220577221..995a8642d 100644 --- a/ishtar_common/migrations/0267_gis_importchunk.py +++ b/ishtar_common/migrations/0269_gis_importchunk.py @@ -7,7 +7,7 @@ import django.db.models.deletion  class Migration(migrations.Migration):      dependencies = [ -        ('ishtar_common', '0266_userrequesttoken_usertoken'), +        ('ishtar_common', '0268_userrequesttoken_usertoken'),      ]      operations = [ diff --git a/ishtar_common/migrations/0268_gis_import_key_init.py b/ishtar_common/migrations/0270_gis_import_key_init.py index 04909f3ee..ed3d8e568 100644 --- a/ishtar_common/migrations/0268_gis_import_key_init.py +++ b/ishtar_common/migrations/0270_gis_import_key_init.py @@ -16,7 +16,7 @@ def update_importkey(apps, __):  class Migration(migrations.Migration):      dependencies = [ -        ('ishtar_common', '0267_gis_importchunk'), +        ('ishtar_common', '0269_gis_importchunk'),      ]      operations = [ diff --git a/ishtar_common/migrations/0269_import_import_immediatly.py b/ishtar_common/migrations/0271_import_import_immediatly.py index cb063cff1..ff94a566b 100644 --- a/ishtar_common/migrations/0269_import_import_immediatly.py +++ b/ishtar_common/migrations/0271_import_import_immediatly.py @@ -6,7 +6,7 @@ from django.db import migrations, models  class Migration(migrations.Migration):      dependencies = [ -        ('ishtar_common', '0268_gis_import_key_init'), +        ('ishtar_common', '0270_gis_import_key_init'),      ]      operations = [ diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 66c29e08d..0ffb24882 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -2732,12 +2732,18 @@ organization_type_pks_lazy = lazy(OrganizationType.get_or_create_pks, str)  class Organization(Address, Merge, OwnPerms, BaseGenderedType, ValueGetter, MainItem): -    TABLE_COLS = ("name", "organization_type", "address", "town") -    # , "precise_town") +    NEW_QUERY_ENGINE = True +    TABLE_COLS = ("name", "organization_type__label", "address", "cached_town")      SLUG = "organization"      SHOW_URL = "show-organization"      DELETE_URL = "delete-organization" +    COL_LABELS = { +        "organization_type__label": _("Organization"), +        "cached_town": _("Town"), +    } +    CACHED_LABELS = ["cached_label", "cached_town"] +      # search parameters      EXTRA_REQUEST_KEYS = {          "precise_town": "precise_town__cached_label" @@ -2981,19 +2987,29 @@ class Person(Address, Merge, OwnPerms, ValueGetter, MainItem):          "surname",          "raw_name",          "email", -        "person_types_list", -        "attached_to", -        "town", +        "cached_person_types", +        "attached_to__name", +        "cached_town",      )      TABLE_COLS_ACCOUNT = (          "name",          "surname",          "raw_name",          "email", -        "profiles_list", -        "attached_to", -        "town", +        "cached_profiles", +        "cached_person_types", +        "attached_to__name", +        "cached_town",      ) +    NEW_QUERY_ENGINE = True +    COL_LABELS = { +        "attached_to__name": _("Organization"), +        "cached_person_types": _("Types"), +        "cached_town": _("Town"), +        "cached_profiles": _("Profiles"), +    } +    CACHED_LABELS = ["cached_label", "cached_person_types", "cached_town", +                     "cached_profiles"]      SHOW_URL = "show-person"      MODIFY_URL = "person_modify"      DELETE_URL = "person_delete" @@ -3014,7 +3030,6 @@ class Person(Address, Merge, OwnPerms, ValueGetter, MainItem):          "ishtaruser__isnull": "ishtaruser__isnull",          "attached_to": "attached_to",      } -    COL_LABELS = {"attached_to": _("Organization"), "person_types_list": _("Types")}      # alternative names of fields for searches      ALT_NAMES = { @@ -3111,6 +3126,12 @@ class Person(Address, Merge, OwnPerms, ValueGetter, MainItem):      cached_label = models.TextField(          _("Cached name"), blank=True, default="", db_index=True      ) +    cached_person_types = models.TextField( +        _("Cached person types"), blank=True, default="" +    ) +    cached_profiles = models.TextField( +        _("Cached profiles"), blank=True, default="" +    )      DOWN_MODEL_UPDATE = ["author"]      class Meta: @@ -3213,6 +3234,12 @@ class Person(Address, Merge, OwnPerms, ValueGetter, MainItem):              lbl += " ({})".format(attached_to)          return lbl +    def _generate_cached_person_types(self): +        return self.person_types_list + +    def _generate_cached_profiles(self): +        return self.profiles_list +      def fancy_str(self):          values = ["<strong>"]          values += [ diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index 96f0f5d86..be3e06848 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -4226,6 +4226,9 @@ class Address(BaseHistorizedItem):      alt_address_is_prefered = models.BooleanField(          _("Alternative address is prefered"), default=False      ) +    cached_town = models.TextField( +        _("Cached town"), blank=True, default="" +    )      history = HistoricalRecords(inherit=True)      SUB_ADDRESSES = []      ALT_NAMES = { @@ -4419,6 +4422,11 @@ class Address(BaseHistorizedItem):      def address_lbl_list(self):          return self.address_lbl(list=True) +    def _generate_cached_town(self): +        if self.precise_town: +            return self.precise_town.name +        return self.town or "" +  class Merge(models.Model):      merge_key = models.TextField(_("Merge key"), blank=True, null=True)  | 
