From f32204381e59d6a6262ea900f17bab483908ca04 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Wed, 2 Mar 2016 15:20:23 +0000 Subject: [PATCH 1/2] Fix autocompleteSort with multiple keys (fixes #2893) QuerySet.order_by() takes each key as a separate argument, not as a single comma-separated string. --- pandora/entity/views.py | 8 ++++---- pandora/item/views.py | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pandora/entity/views.py b/pandora/entity/views.py index 76561cb..c732d70 100644 --- a/pandora/entity/views.py +++ b/pandora/entity/views.py @@ -118,16 +118,16 @@ def autocompleteEntities(request, data): if order_by: for o in order_by: if o['operator'] != '-': - o['operator'] = '' - order_by = ','.join(['%(operator)s%(key)s' % o for o in order_by]) + o['operator'] = '' + order_by = ['%(operator)s%(key)s' % o for o in order_by] else: - order_by = 'name_sort' + order_by = ['name_sort'] qs = models.Entity.objects.filter(type=data['key']) if data['value']: k, v = namePredicate(op, data['value']) qs = qs.filter(**{k: v}) - qs = qs.order_by(order_by) + qs = qs.order_by(*order_by) if op != '$': value_lower = data['value'].lower() matches = [] diff --git a/pandora/item/views.py b/pandora/item/views.py index 9c3cc93..c3296c9 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -311,10 +311,10 @@ def autocomplete(request, data): order_by = key.get('autocompleteSort', False) if order_by: for o in order_by: - if o['operator'] != '-': o['operator'] = '' - order_by = ','.join(['%(operator)ssort__%(key)s' % o for o in order_by]) + if o['operator'] != '-': o['operator'] = '' + order_by = ['%(operator)ssort__%(key)s' % o for o in order_by] else: - order_by = '-items' + order_by = ['-items'] sort_type = key.get('sortType', key.get('type', 'string')) if sort_type == 'title': qs = parse_query({'query': data.get('query', {})}, request.user)['qs'] @@ -327,7 +327,7 @@ def autocomplete(request, data): qs = qs.filter(find__key=data['key'], find__value__istartswith=data['value']) elif op == '$': qs = qs.filter(find__key=data['key'], find__value__iendswith=data['value']) - qs = qs.order_by(order_by, nulls_last=True) + qs = qs.order_by(*order_by, nulls_last=True) qs = qs[data['range'][0]:data['range'][1]] response = json_response({}) response['data']['items'] = list(set([i.get(data['key']) for i in qs])) @@ -346,7 +346,7 @@ def autocomplete(request, 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.order_by(*order_by) qs = qs[data['range'][0]:data['range'][1]] response = json_response({}) response['data']['items'] = [i['value'] for i in qs] -- 2.5.0