fix author sort

This commit is contained in:
j 2015-03-08 18:18:22 +05:30
parent da43cd75e1
commit 61bc1a7267
3 changed files with 11 additions and 3 deletions

View file

@ -12,6 +12,7 @@ from websocket import trigger_event
import metaremote as meta
from . import models
from . import query
from .person import get_sort_name
import settings
import state
import utils
@ -56,7 +57,13 @@ def find(data):
else:
g = []
if 'sort' in q:
g.sort(key=lambda k: k[q['sort'][0]['key']])
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':
return get_sort_name(k[q['sort'][0]['key']])
else:
return k[q['sort'][0]['key']]
g.sort(key=_sort_key)
if q['sort'][0]['operator'] == '-':
g.reverse()
state.cache.set(key, g)

View file

@ -135,11 +135,11 @@ class Item(db.Model):
value = float(value)
elif sort_type == 'date':
pass
elif sort_type == 'name':
elif sort_type == 'person':
if not isinstance(value, list):
value = [value]
value = list(map(get_sort_name, value))
value = ox.sort_string('\n'.join(value))
value = ox.sort_string('\n'.join(value)).lower()
elif sort_type == 'title':
if isinstance(value, dict):
value = list(value.values())

View file

@ -8,6 +8,7 @@ import ox
import sqlalchemy as sa
import db
import state
def get_sort_name(name, sortname=None):