summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2023-05-05 18:38:52 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2023-05-05 18:38:52 +0200
commit3d4ccf95e91b4a6acbe054d149d34daf43aec9c0 (patch)
tree06deb20745ad38e8014452d004169f6e6d60675b /ishtar_common
parenta9c7ae42db56a9b44eb6f84a9e15772ad7ea6739 (diff)
downloadIshtar-3d4ccf95e91b4a6acbe054d149d34daf43aec9c0.tar.bz2
Ishtar-3d4ccf95e91b4a6acbe054d149d34daf43aec9c0.zip
Fix precise_town search
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/models.py4
-rw-r--r--ishtar_common/views_item.py28
2 files changed, 29 insertions, 3 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 3e5b44d8a..c4beb0bff 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -2567,9 +2567,9 @@ class Organization(Address, Merge, OwnPerms, BaseGenderedType, ValueGetter, Main
pgettext_lazy("key for text search", "type"),
"organization_type__label__iexact",
),
- "precise_town": SearchAltName(
+ "precise_town_id": SearchAltName(
pgettext_lazy("key for text search", "precise-town"),
- "precise_town__cached_label__iexact",
+ "precise_town_id__cached_label",
),
}
QA_EDIT = QuickAction(
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index b2b924992..31a96f270 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -1066,7 +1066,33 @@ def _manage_hierarchic_fields(model, dct, and_reqs):
# TODO: improve query with "IN ()"?
continue
- if (
+ if req.endswith("precise_town_id__cached_label"):
+ val = _clean_type_val(dct.pop(req)).strip('"')
+ if val.startswith('"') and val.endswith('"'):
+ val = val[1:-1]
+ vals = [v.replace('"', "") for v in val.split(";")]
+ req = req[:-len("__cached_label")]
+ town_ids = []
+ for val in vals:
+ q = models.Town.objects.filter(cached_label__iexact=val).values_list(
+ "id", flat=True)
+ if not q.count():
+ continue
+ town_id = q.all()[0]
+ town_ids.append(town_id)
+ reqs = Q(**{req: val})
+ for rel_query in ("parents__", "children__"):
+ for idx in range(HIERARCHIC_LEVELS):
+ k = rel_query * (idx + 1) + "pk"
+ q = models.Town.objects.filter(
+ **{k: town_id}).values_list("id", flat=True)
+ if not q.count():
+ break
+ town_ids += list(q.all())
+ main_req = Q(**{req + "__in": town_ids})
+ and_reqs.append(main_req)
+
+ elif (
req.endswith("town__pk")
or req.endswith("towns__pk")
or req.endswith("town__cached_label__iexact")