fix author sort
This commit is contained in:
parent
da43cd75e1
commit
61bc1a7267
3 changed files with 11 additions and 3 deletions
|
@ -12,6 +12,7 @@ from websocket import trigger_event
|
||||||
import metaremote as meta
|
import metaremote as meta
|
||||||
from . import models
|
from . import models
|
||||||
from . import query
|
from . import query
|
||||||
|
from .person import get_sort_name
|
||||||
import settings
|
import settings
|
||||||
import state
|
import state
|
||||||
import utils
|
import utils
|
||||||
|
@ -56,7 +57,13 @@ def find(data):
|
||||||
else:
|
else:
|
||||||
g = []
|
g = []
|
||||||
if 'sort' in q:
|
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'] == '-':
|
if q['sort'][0]['operator'] == '-':
|
||||||
g.reverse()
|
g.reverse()
|
||||||
state.cache.set(key, g)
|
state.cache.set(key, g)
|
||||||
|
|
|
@ -135,11 +135,11 @@ class Item(db.Model):
|
||||||
value = float(value)
|
value = float(value)
|
||||||
elif sort_type == 'date':
|
elif sort_type == 'date':
|
||||||
pass
|
pass
|
||||||
elif sort_type == 'name':
|
elif sort_type == 'person':
|
||||||
if not isinstance(value, list):
|
if not isinstance(value, list):
|
||||||
value = [value]
|
value = [value]
|
||||||
value = list(map(get_sort_name, 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':
|
elif sort_type == 'title':
|
||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
value = list(value.values())
|
value = list(value.values())
|
||||||
|
|
|
@ -8,6 +8,7 @@ import ox
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
|
||||||
import db
|
import db
|
||||||
|
import state
|
||||||
|
|
||||||
|
|
||||||
def get_sort_name(name, sortname=None):
|
def get_sort_name(name, sortname=None):
|
||||||
|
|
Loading…
Reference in a new issue