use secondary sort in filters, fixes #21

This commit is contained in:
j 2016-01-18 16:22:29 +05:30
parent 6dfa62681a
commit 171834bd12

View file

@ -64,14 +64,22 @@ def find(data):
if 'sort' in q: if 'sort' in q:
sort_type = utils.get_by_id(settings.config['itemKeys'], q['group']).get('sortType') sort_type = utils.get_by_id(settings.config['itemKeys'], q['group']).get('sortType')
def _sort_key(k): def _sort_key(k):
if sort_type == 'person' and q['sort'][0]['key'] == 'name': if sort_type == 'person':
v = get_sort_name(k[q['sort'][0]['key']]) name = get_sort_name(k['name'])
else: else:
v = k[q['sort'][0]['key']] name = k['name']
if isinstance(v, str): if isinstance(name, str):
v = unicodedata.normalize('NFKD', v).lower() name = unicodedata.normalize('NFKD', name).lower()
items = k['items']
if q['sort'][0]['key'] == 'name':
v = (name, items)
else:
v = (-items, name)
return v return v
g.sort(key=_sort_key, reverse=q['sort'][0]['operator'] == '-') reverse = q['sort'][0]['operator'] == '-'
if q['sort'][0]['key'] == 'items':
reverse = not reverse
g.sort(key=_sort_key, reverse=reverse)
state.cache.set(key, g) state.cache.set(key, g)
if 'positions' in data: if 'positions' in data:
response['positions'] = {} response['positions'] = {}