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