summaryrefslogtreecommitdiff
path: root/ishtar_common/views_item.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/views_item.py')
-rw-r--r--ishtar_common/views_item.py29
1 files changed, 23 insertions, 6 deletions
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index 639af1e88..d4a975e37 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -2006,12 +2006,18 @@ def _get_table_cols(data_type, own_table_cols, full, model):
def split_dict(dct):
if not dct.get("search_vector", None):
- return [dct]
+ return [("OR", dct)]
new_dcts = []
- for vector in dct["search_vector"].split(" || "):
+
+ # TODO: manage || and && syntax in the same query
+ # example: to extract [[]] parenthesis re.findall(r"(.*)\[\[ (.*?) \]\](.*)", s)
+ split_key, split_type = " || ", "OR"
+ if " && " in dct["search_vector"]:
+ split_key, split_type = " && ", "AND"
+ for vector in dct["search_vector"].split(split_key):
new_dct = deepcopy(dct)
new_dct["search_vector"] = vector
- new_dcts.append(new_dct)
+ new_dcts.append((split_type, new_dct))
return new_dcts
@@ -2566,7 +2572,7 @@ def get_item(
)
items = None
- for sub_dct in split_dict(dct):
+ for split_type, sub_dct in split_dict(dct):
query, exc_query, extras = main_manager(
request,
model,
@@ -2583,7 +2589,7 @@ def get_item(
reversed_many_counted_fields,
my_dated_fields,
my_number_fields,
- and_reqs
+ and_reqs[:]
)
# print("ishtar_common/views_item.py - 2515")
@@ -2602,7 +2608,18 @@ def get_item(
if not items:
items = sub_items
else:
- items |= sub_items
+ if not sub_items.exists():
+ if split_type == "AND":
+ items = model.objects.filter(pk__isnull=True)
+ continue
+ if split_type == "OR":
+ items |= sub_items
+ else:
+ # in Django m2m queries use the same JOIN...
+ # items &= sub_items do not work
+ items &= model.objects.filter(Q(
+ pk__in=list(sub_items.values_list("pk", flat=True))
+ ))
if return_query:
return items