From c216716493cd851548e2057d9902090d9606249a Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 11 Nov 2011 13:31:27 +0100 Subject: [PATCH] support query in autocomplete for keys other than title --- pandora/item/views.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pandora/item/views.py b/pandora/item/views.py index acf9d83f..f03dfbcf 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -292,14 +292,17 @@ def autocomplete(request): param data key value - operator '', '^', '$' + operator '=', '==', '^', '$' + query range return + + query can be an item query to limit results ''' data = json.loads(request.POST['data']) if not 'range' in data: data['range'] = [0, 10] - op = data.get('operator', '') + op = data.get('operator', '==') key = settings.CONFIG['keys'][data['key']] order_by = key.get('autocompleteSortKey', False) @@ -313,6 +316,8 @@ def autocomplete(request): if data['value']: if op == '': qs = qs.filter(find__key=data['key'], find__value__icontains=data['value']) + elif op == '==': + qs = qs.filter(find__key=data['key'], find__value__iexact=data['value']) elif op == '^': qs = qs.filter(find__key=data['key'], find__value__istartswith=data['value']) elif op == '$': @@ -324,12 +329,17 @@ def autocomplete(request): else: qs = models.Facet.objects.filter(key=data['key']) if data['value']: - if op == '': + if op == '=': qs = qs.filter(value__icontains=data['value']) + elif op == '==': + qs = qs.filter(value__iexact=data['value']) elif op == '^': qs = qs.filter(value__istartswith=data['value']) elif op == '$': qs = qs.filter(value__iendswith=data['value']) + if 'query' in data: + item_query = parse_query({'query': data.get('query', {})}, request.user)['qs'] + qs = qs.filter(item__in=item_query) qs = qs.values('value').annotate(items=Count('id')) qs = qs.order_by(order_by) qs = qs[data['range'][0]:data['range'][1]]