summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-06-18 13:18:15 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-06-18 13:18:15 +0200
commitb0254d998afe249471fe88f15dfc35dce46a2c5e (patch)
tree191bb3c023094df3758d66e10525056db6fffc13
parentaa410b7d8e089228ef1bc0d09512d7e00117b9d5 (diff)
downloadIshtar-b0254d998afe249471fe88f15dfc35dce46a2c5e.tar.bz2
Ishtar-b0254d998afe249471fe88f15dfc35dce46a2c5e.zip
Free search: manage by default with startswith
-rw-r--r--ishtar_common/views_item.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index 53c65c3aa..93ab133a0 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -499,15 +499,17 @@ def _parse_query_string(string, query_parameters, current_dct, exc_dct,
if len(string) != 1:
for reserved_char in RESERVED_CHAR:
string = string.replace(reserved_char, u"")
- # like search
if string.endswith(u'*'):
if len(string.strip()) == 1:
return u""
- string = string[:-1] + u':*'
- if string.startswith(u'-'):
+ string = string[:-1] + ':*'
+ elif string not in ("&", "|", "!", "-"):
+ # like search by default
+ string = string + ':*'
+ if string.startswith('-'):
if len(string.strip()) == 1:
- return u""
- string = u"!" + string[1:]
+ return ""
+ string = "!" + string[1:]
return string
@@ -874,9 +876,9 @@ def _manage_hierarchic_fields(dct, and_reqs):
if val.endswith(u'"') and val.startswith(u'"'):
val = val[1:-1]
# manage search text by label
- if u"*" in val:
+ if "*" in val:
suffix = "label__icontains"
- val = val.replace(u'*', u"")
+ val = val.replace('*', u"")
else:
suffix = "label__iexact"
req = req[:-(len(base_suffix))] + suffix
@@ -902,9 +904,9 @@ def _manage_clean_search_field(dct):
dct[k] = _clean_type_val(dct[k])
if '*' in dct[k] and k.endswith('__iexact'):
value = dct.pop(k).strip()
- if value.startswith(u"*"):
+ if value.startswith("*"):
value = value[1:]
- if value.endswith(u"*"):
+ if value.endswith("*"):
value = value[:-1]
dct[k[:-len('__iexact')] + '__icontains'] = value