summaryrefslogtreecommitdiff
path: root/archaeological_warehouse
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2021-04-29 17:33:58 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-04-29 18:13:13 +0200
commitc07fd7b41ea253010d5b6249cc0fdbaa4324102b (patch)
treed543b9996c87ec8a651fa79b31566caaa566a16f /archaeological_warehouse
parentab9d8fba4fc19e068b084f6827a9ebc255f926a4 (diff)
downloadIshtar-c07fd7b41ea253010d5b6249cc0fdbaa4324102b.tar.bz2
Ishtar-c07fd7b41ea253010d5b6249cc0fdbaa4324102b.zip
Fix autocomplete container and default basket search
Diffstat (limited to 'archaeological_warehouse')
-rw-r--r--archaeological_warehouse/views.py47
1 files changed, 24 insertions, 23 deletions
diff --git a/archaeological_warehouse/views.py b/archaeological_warehouse/views.py
index 54390aca9..e79e291ec 100644
--- a/archaeological_warehouse/views.py
+++ b/archaeological_warehouse/views.py
@@ -186,29 +186,30 @@ 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 itertools.permutations(type_positions):
- groups = []
- for idx, (container_type_id, pos_inf, pos_sup) in enumerate(positions):
- 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:min(next_positions)])
- if value:
- groups.append((container_type_id, value))
- 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 type_positions:
+ for positions in itertools.permutations(type_positions):
+ groups = []
+ for idx, (container_type_id, pos_inf, pos_sup) in enumerate(positions):
+ 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:min(next_positions)])
+ if value:
+ groups.append((container_type_id, value))
+ 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