use secondary sort in filters, fixes #21
This commit is contained in:
parent
6dfa62681a
commit
171834bd12
1 changed files with 14 additions and 6 deletions
|
@ -64,14 +64,22 @@ def find(data):
|
|||
if 'sort' in q:
|
||||
sort_type = utils.get_by_id(settings.config['itemKeys'], q['group']).get('sortType')
|
||||
def _sort_key(k):
|
||||
if sort_type == 'person' and q['sort'][0]['key'] == 'name':
|
||||
v = get_sort_name(k[q['sort'][0]['key']])
|
||||
if sort_type == 'person':
|
||||
name = get_sort_name(k['name'])
|
||||
else:
|
||||
v = k[q['sort'][0]['key']]
|
||||
if isinstance(v, str):
|
||||
v = unicodedata.normalize('NFKD', v).lower()
|
||||
name = k['name']
|
||||
if isinstance(name, str):
|
||||
name = unicodedata.normalize('NFKD', name).lower()
|
||||
items = k['items']
|
||||
if q['sort'][0]['key'] == 'name':
|
||||
v = (name, items)
|
||||
else:
|
||||
v = (-items, name)
|
||||
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)
|
||||
if 'positions' in data:
|
||||
response['positions'] = {}
|
||||
|
|
Loading…
Reference in a new issue