summaryrefslogtreecommitdiff
path: root/ishtar_common/views_item.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-07-04 11:43:34 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-08-13 18:26:03 +0200
commitb83bc8404f77600e8d313d9cdd6672d8208de01f (patch)
tree7c570daeb42e18b384f4069751935b507b0da767 /ishtar_common/views_item.py
parentaf27a6bb1e153b0c20cfed9c645b30adedde3347 (diff)
downloadIshtar-b83bc8404f77600e8d313d9cdd6672d8208de01f.tar.bz2
Ishtar-b83bc8404f77600e8d313d9cdd6672d8208de01f.zip
Search: do not parse for parentheses inside quotes (refs #4180)
Diffstat (limited to 'ishtar_common/views_item.py')
-rw-r--r--ishtar_common/views_item.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index d2e66ae69..a818c2719 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -295,15 +295,21 @@ def _parse_parentheses(s):
groups = []
depth = 0
+ inside_quote = False
for char in s:
- if char == u'(':
- _push_to_list([], groups, depth)
- depth += 1
- elif char == ')':
- if depth > 0:
- depth -= 1
- else:
- _push_to_list(char, groups, depth)
+ if char == u'"':
+ inside_quote = not inside_quote
+ if not inside_quote:
+ if char == u'(':
+ _push_to_list([], groups, depth)
+ depth += 1
+ elif char == u')':
+ if depth > 0:
+ depth -= 1
+ else:
+ _push_to_list(char, groups, depth)
+ continue
+ _push_to_list(char, groups, depth)
# for non tolerant to parentheses mismatch check depth is equal to 0
return groups
@@ -643,7 +649,6 @@ def _contruct_query(relation_types, dct, or_reqs, and_reqs):
# manage multi value not already managed
for key in dct.keys():
if ";" in dct[key]:
- print(key, dct[key])
values = [v for v in dct[key].split(u';') if v]
if not values:
dct.pop(key)
@@ -958,6 +963,7 @@ def get_item(model, func_name, default_name, extra_request_keys=[],
dct = {upper_key: current}
query &= Q(**dct)
+ # print(query)
items = model.objects.filter(query)
if exc_query:
items = items.exclude(exc_query)