diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-04-28 12:10:32 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-04-28 12:18:07 +0200 |
commit | a9426e4ede27ff683295fa40930c578274e445fd (patch) | |
tree | 2df5ad0561d81e7bceb4090d9d4451e915b7740c | |
parent | 82097e9a5bf31134a8a3cff2bfc06337d529f878 (diff) | |
download | Ishtar-a9426e4ede27ff683295fa40930c578274e445fd.tar.bz2 Ishtar-a9426e4ede27ff683295fa40930c578274e445fd.zip |
Container autocomplete: allow any order in container types
-rw-r--r-- | CHANGES.md | 8 | ||||
-rw-r--r-- | archaeological_warehouse/views.py | 35 | ||||
-rw-r--r-- | ishtar_common/version.py | 4 |
3 files changed, 27 insertions, 20 deletions
diff --git a/CHANGES.md b/CHANGES.md index 5c5e304f2..d2d7a3873 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,11 +1,17 @@ Ishtar changelog ================ +v3.1.15 - 2021-04-28 +-------------------- + +### Features ### +- Better filter on container autocomplete - manage any order in parent types + v3.1.14 - 2021-04-28 -------------------- ### Features ### -- Better filter on container autocomplete - manage unaccent any order in parent +- Better filter on container autocomplete - manage unaccent - reversed order in parent v3.1.13 - 2021-04-20 -------------------- diff --git a/archaeological_warehouse/views.py b/archaeological_warehouse/views.py index c6072a4df..54390aca9 100644 --- a/archaeological_warehouse/views.py +++ b/archaeological_warehouse/views.py @@ -18,6 +18,7 @@ # See the file COPYING for details. import json +import itertools from unidecode import unidecode from django.core.urlresolvers import reverse @@ -185,29 +186,29 @@ def autocomplete_container(request, warehouse_id=None): query &= Q(location__name__icontains=splitted[idx]) # group by container type, ref tuple # can be in any order - for positions in (type_positions, list(reversed(type_positions))): + for positions in itertools.permutations(type_positions): groups = [] for idx, (container_type_id, pos_inf, pos_sup) in enumerate(positions): - if len(positions) == idx + 1: # last + next_positions = [p[1] for p in positions + if p[0] != container_type_id and p[1] > pos_sup] + if not next_positions: value = " ".join(splitted[pos_sup:]) else: - value = " ".join(splitted[pos_sup:positions[idx + 1][1]]) + value = " ".join(splitted[pos_sup:min(next_positions)]) if value: groups.append((container_type_id, value)) - if groups: - for gp in (groups, reversed(groups)): - query = base_query - for idx, g in enumerate(gp): - base_key = "parent__" * idx - key1 = base_key + "container_type_id" - key2 = base_key + "reference__unaccent__iexact" - query &= Q(**{key1: g[0], key2: g[1]}) - ids = {c["id"] for c in containers} - containers += list( - models.Container.objects.filter(query) - .exclude(pk__in=ids) - .values("id", "cached_label")[:limit] - ) + query = base_query + for idx, g in enumerate(groups): + base_key = "parent__" * idx + key1 = base_key + "container_type_id" + key2 = base_key + "reference__unaccent__iexact" + query &= Q(**{key1: g[0], key2: g[1]}) + ids = {c["id"] for c in containers} + containers += list( + models.Container.objects.filter(query) + .exclude(pk__in=ids) + .values("id", "cached_label")[:limit] + ) if len(splitted) > 1 and len(containers) < 15: # group to do a "type" "reference" search diff --git a/ishtar_common/version.py b/ishtar_common/version.py index cee8b8d69..49401545c 100644 --- a/ishtar_common/version.py +++ b/ishtar_common/version.py @@ -1,5 +1,5 @@ -# 3.1.14 -VERSION = (3, 1, 14) +# 3.1.15 +VERSION = (3, 1, 15) def get_version(): |