only decode ids for found positions

merge document.view.get_positions into item.utils.get_positions
add flag to decode id before looking up in ids

Followup to 09ebbc9cc6
This commit is contained in:
j 2016-06-30 16:18:07 +02:00
commit c7157d5001
12 changed files with 24 additions and 47 deletions

View file

@ -61,7 +61,7 @@ def sort_title(title):
title = re.sub(u'[\'!¿¡,\.;\-"\:\*\[\]]', '', title)
return title.strip()
def get_positions(ids, pos):
def get_positions(ids, pos, decode_id=False):
'''
>>> get_positions([1,2,3,4], [2,4])
{2: 1, 4: 3}
@ -69,7 +69,10 @@ def get_positions(ids, pos):
positions = {}
for i in pos:
try:
positions[i] = ids.index(i)
if decode_id:
positions[i] = ids.index(ox.fromAZ(i))
else:
positions[i] = ids.index(i)
except:
pass
return positions

View file

@ -204,7 +204,7 @@ def find(request, data):
response['data']['position'] = utils.get_positions(ids, [qs[0].public_id])[0]
elif 'positions' in query:
qs = _order_query(query['qs'], query['sort'])
ids = [j['public_id'] for j in qs.values('public_id')]
ids = list(qs.values_list('public_id', flat=True))
response['data']['positions'] = utils.get_positions(ids, query['positions'])
elif 'keys' in query:
response['data']['items'] = []