summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/migrations/0265_cached_town.py53
-rw-r--r--ishtar_common/migrations/0266_migrate_cached_town.py37
-rw-r--r--ishtar_common/models.py45
-rw-r--r--ishtar_common/models_common.py8
4 files changed, 134 insertions, 9 deletions
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/models.py b/ishtar_common/models.py
index 95dd5cac2..00c17db14 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -2730,12 +2730,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"
@@ -2979,19 +2985,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": _("Person 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"
@@ -3012,7 +3028,6 @@ class Person(Address, Merge, OwnPerms, ValueGetter, MainItem):
"ishtaruser__isnull": "ishtaruser__isnull",
"attached_to": "attached_to",
}
- COL_LABELS = {"attached_to": _("Organization")}
# alternative names of fields for searches
ALT_NAMES = {
@@ -3109,6 +3124,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:
@@ -3211,6 +3232,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 ce31cb974..75aa6c986 100644
--- a/ishtar_common/models_common.py
+++ b/ishtar_common/models_common.py
@@ -4201,6 +4201,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 = {
@@ -4394,6 +4397,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)