summaryrefslogtreecommitdiff
path: root/ishtar_common/views_item.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2025-02-10 12:39:46 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2025-02-19 14:45:57 +0100
commit24417581e8d32f8f3a3ebba2bf4292efdb87230a (patch)
tree5d8dae24b2e4c146e3fbfd428a41d0499ab132bf /ishtar_common/views_item.py
parent7afcbc6e7a64364dd2a8164974e23c6e405a0165 (diff)
downloadIshtar-24417581e8d32f8f3a3ebba2bf4292efdb87230a.tar.bz2
Ishtar-24417581e8d32f8f3a3ebba2bf4292efdb87230a.zip
🐛 fix many area searches (refs #6125)
Diffstat (limited to 'ishtar_common/views_item.py')
-rw-r--r--ishtar_common/views_item.py58
1 files changed, 35 insertions, 23 deletions
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index a9294cec4..7ee3742d2 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -1390,35 +1390,47 @@ def _manage_hierarchic_precise_town_area(req, dct, and_reqs):
and_reqs.append(reqs)
-def _manage_hierarchic_area(req, dct, and_reqs):
- if req.endswith("pk"):
+def _manage_hierarchic_area(base_req, dct, and_reqs):
+ if base_req.endswith("pk"):
suffix = "pk"
- elif req.endswith("label__iexact"):
+ elif base_req.endswith("label__iexact"):
suffix = "label__iexact"
else:
return
- val = _clean_type_val(dct.pop(req))
- if val.startswith('"') and val.endswith('"'):
- val = val[1:-1]
- if val == "*":
- req = req.replace("label__", "").replace("pk", "").replace("iexact", "")
- req += "isnull"
- reqs = Q(**{req: False})
- and_reqs.append(reqs)
- return
- elif "*" in val and "iexact" in suffix:
- suffix = suffix.replace("iexact", "icontains")
- req = req.replace("iexact", "icontains")
- val = val.replace("*", "")
+ vals = _clean_type_val(dct.pop(base_req))
+ query_list = []
+ for val in vals.split(";"):
+ req = base_req[:]
+ if val.startswith('"'):
+ val = val[1:]
+ if val.endswith('"'):
+ val = val[:-1]
+ if val == "*":
+ req = req.replace("label__", "").replace("pk", "").replace("iexact", "")
+ req += "isnull"
+ reqs = Q(**{req: False})
+ and_reqs.append(reqs)
+ return
+ elif "*" in val and "iexact" in suffix:
+ suffix = suffix.replace("iexact", "icontains")
+ req = req.replace("iexact", "icontains")
+ val = val.replace("*", "")
- reqs = Q(**{req: val})
+ reqs = Q(**{req: val})
- for idx in range(HIERARCHIC_LEVELS):
- req = req[: -(len(suffix))] + "parent__" + suffix
- q = Q(**{req: val})
- reqs |= q
- and_reqs.append(reqs)
- # TODO: improve query with "IN ()"?
+ for idx in range(HIERARCHIC_LEVELS):
+ req = req[: -(len(suffix))] + "parent__" + suffix
+ q = Q(**{req: val})
+ reqs |= q
+ query_list.append(reqs)
+ # TODO: improve query with "IN ()"?
+ if not query_list:
+ return
+ q = query_list[0]
+ for query in query_list[1:]:
+ q |= query
+ print(q)
+ and_reqs.append(q)
def _manage_hierarchic_fields(model, dct, and_reqs):