diff options
author | Ătienne Loks <etienne.loks@iggdrasil.net> | 2023-07-03 18:11:28 +0200 |
---|---|---|
committer | Ătienne Loks <etienne.loks@iggdrasil.net> | 2023-07-03 18:19:22 +0200 |
commit | 7ca43bf432f679dab4a834e81ad5b708fbbb06b0 (patch) | |
tree | d74a3632bc612c9d4405f9865ac36b90e63515fa | |
parent | 6e10770d2c121a88be0368c8764c47596bc884ba (diff) | |
download | Ishtar-7ca43bf432f679dab4a834e81ad5b708fbbb06b0.tar.bz2 Ishtar-7ca43bf432f679dab4a834e81ad5b708fbbb06b0.zip |
đ Fix "*" search for text fields (refs #5325)
-rw-r--r-- | archaeological_finds/tests.py | 21 | ||||
-rw-r--r-- | changelog/en/changelog_2022-06-15.md | 1 | ||||
-rw-r--r-- | changelog/fr/changelog_2023-01-25.md | 1 | ||||
-rw-r--r-- | ishtar_common/views_item.py | 14 |
4 files changed, 31 insertions, 6 deletions
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py index d4a02b94d..b4612619b 100644 --- a/archaeological_finds/tests.py +++ b/archaeological_finds/tests.py @@ -1391,6 +1391,27 @@ class FindSearchTest(FindInit, TestCase, SearchText): result = [('{}="{}"'.format(key, "Operation Common Name"), 1)] self._test_search(c, result, context="Text Operation Common Name Search") + def test_description_search(self): + find = self.finds[0] + find.description = "A simple description." + find.save() + find2 = self.finds[1] + find2.description = "" + find2.save() + self.create_finds() + self.create_finds() + + c = Client() + c.login(username=self.username, password=self.password) + + key = str(pgettext_lazy("key for text search", "description")) + result = [('{}="{}"'.format(key, "A simple description."), 1)] + self._test_search(c, result, context="Text description Search") + result = [('{}="{}"'.format(key, "*"), 1)] + self._test_search(c, result, context="* description Search") + result = [('-{}="{}"'.format(key, "*"), models.Find.objects.count() - 1)] + self._test_search(c, result, context="-* description Search") + def test_address_operation_search(self): operation = self.operations[0] operation.address = "Street somewhere 29478 NOWHERE" diff --git a/changelog/en/changelog_2022-06-15.md b/changelog/en/changelog_2022-06-15.md index 6a172482d..835aeffc7 100644 --- a/changelog/en/changelog_2022-06-15.md +++ b/changelog/en/changelog_2022-06-15.md @@ -8,6 +8,7 @@ v4.0.50 - 2999-12-31 ### Bug fixes ### - Operation form: the operation code field (Patriarche) is no longer optional +- fix "*" search for text fields (refs #5325) - forms - unit input: fix round float display - sheet: fix float display for hectare - fix crash on qrcode generation for base finds diff --git a/changelog/fr/changelog_2023-01-25.md b/changelog/fr/changelog_2023-01-25.md index fc3b42bdf..358d70615 100644 --- a/changelog/fr/changelog_2023-01-25.md +++ b/changelog/fr/changelog_2023-01-25.md @@ -8,6 +8,7 @@ v4.0.50 - 2999-12-31 ### Corrections de dysfonctionnements ### - Formulaire opération : le champ code opération (Patriarche) n'est plus facultatif +- Correction de la recherche "*" pour les champs texte (refs #5325) - Formulaires - champ unité : correction des arrondis des flottants - Fiche : correction de l'affichage à virgule pour les hectares - Correction d'erreur lors de la génération de qrcode pour le mobilier d'origine diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index e2214d5dc..1cb0b80f2 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -1209,7 +1209,7 @@ def _manage_hierarchic_fields(model, dct, and_reqs): break -def _manage_clean_search_field(dct, exclude=None): +def _manage_clean_search_field(dct, exclude=None, reverse=False): for k in list(dct.keys()): # clean quoted search field if type(dct[k]) != str: @@ -1221,10 +1221,10 @@ def _manage_clean_search_field(dct, exclude=None): value = dct.pop(k).strip() base_key = k[:-len("__iexact")] if value == "*": - dct[base_key + "__isnull"] = False - # TODO search - #if exclude is not None: - # exclude[base_key + "__exact"] = "" + if not reverse: + dct[base_key + "__isnull"] = False + if exclude is not None: + exclude[base_key + "__exact"] = "" continue if value.startswith("*"): value = value[1:] @@ -1301,6 +1301,8 @@ def _construct_query(relation_types, dct, or_reqs, and_reqs, excluded_relation=F values = [v for v in dct[key].split(";") if v] else: values = [dct[key]] + if not values: + values = [""] # filter empty value for value in values: or_reqs.append((key, {key: value})) dct = {} @@ -2132,7 +2134,7 @@ def get_item( updated_excluded = {} _manage_clean_search_field(dct, updated_excluded) - _manage_clean_search_field(excluded_dct, dct) + _manage_clean_search_field(excluded_dct, dct, reverse=True) if updated_excluded: excluded_dct.update(updated_excluded) |