forked from 0x2620/pandora
Fix autocompleteSort with multiple keys (fixes #2893)
QuerySet.order_by() takes each key as a separate argument, not as a single comma-separated string.
This commit is contained in:
parent
2a07e2a1ab
commit
c6f9f87c8e
2 changed files with 9 additions and 9 deletions
|
@ -119,15 +119,15 @@ def autocompleteEntities(request, data):
|
||||||
for o in order_by:
|
for o in order_by:
|
||||||
if o['operator'] != '-':
|
if o['operator'] != '-':
|
||||||
o['operator'] = ''
|
o['operator'] = ''
|
||||||
order_by = ','.join(['%(operator)s%(key)s' % o for o in order_by])
|
order_by = ['%(operator)s%(key)s' % o for o in order_by]
|
||||||
else:
|
else:
|
||||||
order_by = 'name_sort'
|
order_by = ['name_sort']
|
||||||
|
|
||||||
qs = models.Entity.objects.filter(type=data['key'])
|
qs = models.Entity.objects.filter(type=data['key'])
|
||||||
if data['value']:
|
if data['value']:
|
||||||
k, v = namePredicate(op, data['value'])
|
k, v = namePredicate(op, data['value'])
|
||||||
qs = qs.filter(**{k: v})
|
qs = qs.filter(**{k: v})
|
||||||
qs = qs.order_by(order_by)
|
qs = qs.order_by(*order_by)
|
||||||
if op != '$':
|
if op != '$':
|
||||||
value_lower = data['value'].lower()
|
value_lower = data['value'].lower()
|
||||||
matches = []
|
matches = []
|
||||||
|
|
|
@ -312,9 +312,9 @@ def autocomplete(request, data):
|
||||||
if order_by:
|
if order_by:
|
||||||
for o in order_by:
|
for o in order_by:
|
||||||
if o['operator'] != '-': o['operator'] = ''
|
if o['operator'] != '-': o['operator'] = ''
|
||||||
order_by = ','.join(['%(operator)ssort__%(key)s' % o for o in order_by])
|
order_by = ['%(operator)ssort__%(key)s' % o for o in order_by]
|
||||||
else:
|
else:
|
||||||
order_by = '-items'
|
order_by = ['-items']
|
||||||
sort_type = key.get('sortType', key.get('type', 'string'))
|
sort_type = key.get('sortType', key.get('type', 'string'))
|
||||||
if sort_type == 'title':
|
if sort_type == 'title':
|
||||||
qs = parse_query({'query': data.get('query', {})}, request.user)['qs']
|
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'])
|
qs = qs.filter(find__key=data['key'], find__value__istartswith=data['value'])
|
||||||
elif op == '$':
|
elif op == '$':
|
||||||
qs = qs.filter(find__key=data['key'], find__value__iendswith=data['value'])
|
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]]
|
qs = qs[data['range'][0]:data['range'][1]]
|
||||||
response = json_response({})
|
response = json_response({})
|
||||||
response['data']['items'] = list(set([i.get(data['key']) for i in qs]))
|
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']
|
item_query = parse_query({'query': data.get('query', {})}, request.user)['qs']
|
||||||
qs = qs.filter(item__in=item_query)
|
qs = qs.filter(item__in=item_query)
|
||||||
qs = qs.values('value').annotate(items=Count('id'))
|
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]]
|
qs = qs[data['range'][0]:data['range'][1]]
|
||||||
response = json_response({})
|
response = json_response({})
|
||||||
response['data']['items'] = [i['value'] for i in qs]
|
response['data']['items'] = [i['value'] for i in qs]
|
||||||
|
|
Loading…
Reference in a new issue