mirror of
https://github.com/beetbox/beets.git
synced 2025-12-14 20:43:41 +01:00
Remove special_sorts
These are not extensible anyway; we'll need another mechanism for that.
This commit is contained in:
parent
76c831a1cd
commit
369533d46f
3 changed files with 12 additions and 36 deletions
|
|
@ -638,34 +638,22 @@ class FixedFieldSort(FieldSort):
|
|||
|
||||
|
||||
class SmartArtistSort(Sort):
|
||||
""" Sort Album or Item on artist sort fields, defaulting back on
|
||||
artist field if the sort specific field is empty.
|
||||
"""Sort by artist (either album artist or track artist),
|
||||
prioritizing the sort field over the raw field.
|
||||
"""
|
||||
def __init__(self, model_cls, is_ascending=True):
|
||||
self.model_cls = model_cls
|
||||
self.is_ascending = is_ascending
|
||||
|
||||
def select_clause(self):
|
||||
return ""
|
||||
|
||||
def union_clause(self):
|
||||
return ""
|
||||
|
||||
def order_clause(self):
|
||||
order = "ASC" if self.is_ascending else "DESC"
|
||||
if 'albumartist_sort' in self.model_cls._fields:
|
||||
exp1 = 'albumartist_sort'
|
||||
exp2 = 'albumartist'
|
||||
elif 'artist_sort' in self.model_cls_fields:
|
||||
exp1 = 'artist_sort'
|
||||
exp2 = 'artist'
|
||||
if 'albumartist' in self.model_cls._fields:
|
||||
field = 'albumartist'
|
||||
else:
|
||||
return ""
|
||||
|
||||
order_str = ('(CASE {0} WHEN NULL THEN {1} '
|
||||
'WHEN "" THEN {1} '
|
||||
'ELSE {0} END) {2} ').format(exp1, exp2, order)
|
||||
return order_str
|
||||
field = 'artist'
|
||||
return ('(CASE {0}_sort WHEN NULL THEN {0} '
|
||||
'WHEN "" THEN {0} '
|
||||
'ELSE {0}_sort END) {2} ').format(field, order)
|
||||
|
||||
|
||||
class SlowFieldSort(FieldSort):
|
||||
|
|
@ -676,9 +664,6 @@ class SlowFieldSort(FieldSort):
|
|||
return True
|
||||
|
||||
|
||||
special_sorts = {'smartartist': SmartArtistSort}
|
||||
|
||||
|
||||
def build_sql(model_cls, query, sort):
|
||||
""" Generate a sql statement (and the values that must be injected into it)
|
||||
from a query, sort and a model class. Query and sort objects are returned
|
||||
|
|
|
|||
|
|
@ -131,10 +131,11 @@ def construct_sort_part(model_cls, part):
|
|||
is_ascending = (part[-1] == '+')
|
||||
if field in model_cls._fields:
|
||||
sort = query.FixedFieldSort(field, is_ascending)
|
||||
elif field in query.special_sorts:
|
||||
sort = query.special_sorts[field](model_cls, is_ascending)
|
||||
elif field == 'smartartist':
|
||||
# Special case for smart artist sort.
|
||||
sort = query.SmartArtistSort(model_cls, is_ascending)
|
||||
else:
|
||||
# Flexible or comptued.
|
||||
# Flexible or computed.
|
||||
sort = query.SlowFieldSort(field, is_ascending)
|
||||
return sort
|
||||
|
||||
|
|
|
|||
|
|
@ -139,16 +139,6 @@ class MusicalKey(types.String):
|
|||
PF_KEY_DEFAULT = 'default'
|
||||
|
||||
|
||||
# A little SQL utility.
|
||||
def _orelse(exp1, exp2):
|
||||
"""Generates an SQLite expression that evaluates to exp1 if exp1 is
|
||||
non-null and non-empty or exp2 otherwise.
|
||||
"""
|
||||
return ("""(CASE {0} WHEN NULL THEN {1}
|
||||
WHEN "" THEN {1}
|
||||
ELSE {0} END)""").format(exp1, exp2)
|
||||
|
||||
|
||||
# Exceptions.
|
||||
|
||||
class FileOperationError(Exception):
|
||||
|
|
|
|||
Loading…
Reference in a new issue