diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-04-08 17:53:45 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-04-24 19:42:35 +0200 |
commit | 746d25570b885a90895fb2783a8c624406c4ba24 (patch) | |
tree | 501f7aaef98bd9d80ab93c80aafe8913548898c7 | |
parent | 373cc7ea161d77a106b75d11f5c40319be21f4d0 (diff) | |
download | Ishtar-746d25570b885a90895fb2783a8c624406c4ba24.tar.bz2 Ishtar-746d25570b885a90895fb2783a8c624406c4ba24.zip |
Search: manage asterisk inside search query (refs #4480)
-rw-r--r-- | archaeological_operations/tests.py | 12 | ||||
-rw-r--r-- | ishtar_common/views_item.py | 6 |
2 files changed, 17 insertions, 1 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 3f659ef3b..b5680a6fd 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -1814,6 +1814,18 @@ class OperationSearchTest(TestCase, OperationInitTest): self._test_search(c, search_name_q, lbl, 1, "Facet search with = and | characters") + def test_search_with_asterisk_inside_names(self): + c = Client() + c.login(username=self.username, password=self.password) + ope = self.operations[0] + ope_type = ope.operation_type + ope_type.label = 'label*with*asterisk' + ope_type.save() + search_name_q = str(pgettext("key for text search", u"type")) + nb = models.Operation.objects.filter(operation_type=ope_type).count() + self._test_search(c, search_name_q, ope_type.label, nb, + "Facet search with * characters") + def test_hierarchic_search(self): ope = self.operations[1] c = Client() diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index a2e0844ce..2fdda5efb 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -841,7 +841,11 @@ def _manage_clean_search_field(dct): dct[k] = dct[k].replace(u'"', '') dct[k] = _clean_type_val(dct[k]) if '*' in dct[k] and k.endswith('__iexact'): - value = dct.pop(k).replace(u'*', u'') + value = dct.pop(k).strip() + if value.startswith(u"*"): + value = value[1:] + if value.endswith(u"*"): + value = value[:-1] dct[k[:-len('__iexact')] + '__icontains'] = value |