mirror of
https://github.com/beetbox/beets.git
synced 2025-12-15 04:55:10 +01:00
Sort is case insensitive by default
Renamed "ignore_case" to more canonical "case_insensitive"
This commit is contained in:
parent
18d262a59c
commit
2ce38a254e
4 changed files with 14 additions and 13 deletions
|
|
@ -67,7 +67,7 @@ time_format: '%Y-%m-%d %H:%M:%S'
|
|||
|
||||
sort_album: albumartist+ album+
|
||||
sort_item: artist+ album+ disc+ track+
|
||||
sort_ignore_case: no
|
||||
sort_case_insensitive: yes
|
||||
|
||||
paths:
|
||||
default: $albumartist/$album%aunique{}/$track $title
|
||||
|
|
|
|||
|
|
@ -717,10 +717,10 @@ class FieldSort(Sort):
|
|||
"""An abstract sort criterion that orders by a specific field (of
|
||||
any kind).
|
||||
"""
|
||||
def __init__(self, field, ascending=True, ignore_case=False):
|
||||
def __init__(self, field, ascending=True, case_insensitive=True):
|
||||
self.field = field
|
||||
self.ascending = ascending
|
||||
self.ignore_case = ignore_case
|
||||
self.case_insensitive = case_insensitive
|
||||
|
||||
def sort(self, objs):
|
||||
# TODO: Conversion and null-detection here. In Python 3,
|
||||
|
|
@ -729,7 +729,7 @@ class FieldSort(Sort):
|
|||
|
||||
def key(item):
|
||||
field_val = getattr(item, self.field)
|
||||
if self.ignore_case and isinstance(field_val, unicode):
|
||||
if self.case_insensitive and isinstance(field_val, unicode):
|
||||
field_val = field_val.lower()
|
||||
return field_val
|
||||
|
||||
|
|
@ -756,7 +756,7 @@ class FixedFieldSort(FieldSort):
|
|||
"""
|
||||
def order_clause(self):
|
||||
order = "ASC" if self.ascending else "DESC"
|
||||
collate = 'COLLATE NOCASE' if self.ignore_case else ''
|
||||
collate = 'COLLATE NOCASE' if self.case_insensitive else ''
|
||||
return "{0} {1} {2}".format(self.field, collate, order)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -138,14 +138,15 @@ def construct_sort_part(model_cls, part):
|
|||
assert direction in ('+', '-'), "part must end with + or -"
|
||||
is_ascending = direction == '+'
|
||||
|
||||
ignore_case = beets.config['sort_ignore_case'].get(bool)
|
||||
case_insensitive = beets.config['sort_case_insensitive'].get(bool)
|
||||
if field in model_cls._sorts:
|
||||
sort = model_cls._sorts[field](model_cls, is_ascending, ignore_case)
|
||||
sort = model_cls._sorts[field](model_cls, is_ascending,
|
||||
case_insensitive)
|
||||
elif field in model_cls._fields:
|
||||
sort = query.FixedFieldSort(field, is_ascending, ignore_case)
|
||||
sort = query.FixedFieldSort(field, is_ascending, case_insensitive)
|
||||
else:
|
||||
# Flexible or computed.
|
||||
sort = query.SlowFieldSort(field, is_ascending, ignore_case)
|
||||
sort = query.SlowFieldSort(field, is_ascending, case_insensitive)
|
||||
return sort
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -197,15 +197,15 @@ class SmartArtistSort(dbcore.query.Sort):
|
|||
"""Sort by artist (either album artist or track artist),
|
||||
prioritizing the sort field over the raw field.
|
||||
"""
|
||||
def __init__(self, model_cls, ascending=True, ignore_case=False):
|
||||
def __init__(self, model_cls, ascending=True, case_insensitive=True):
|
||||
self.album = model_cls is Album
|
||||
self.ascending = ascending
|
||||
self.ignore_case = ignore_case
|
||||
self.case_insensitive = case_insensitive
|
||||
|
||||
def order_clause(self):
|
||||
order = "ASC" if self.ascending else "DESC"
|
||||
field = 'albumartist' if self.album else 'artist'
|
||||
collate = 'COLLATE NOCASE' if self.ignore_case else ''
|
||||
collate = 'COLLATE NOCASE' if self.case_insensitive else ''
|
||||
return ('(CASE {0}_sort WHEN NULL THEN {0} '
|
||||
'WHEN "" THEN {0} '
|
||||
'ELSE {0}_sort END) {1} {2}').format(field, collate, order)
|
||||
|
|
@ -216,7 +216,7 @@ class SmartArtistSort(dbcore.query.Sort):
|
|||
else:
|
||||
field = lambda i: i.artist_sort or i.artist
|
||||
|
||||
if self.ignore_case:
|
||||
if self.case_insensitive:
|
||||
key = lambda x: field(x).lower()
|
||||
else:
|
||||
key = field
|
||||
|
|
|
|||
Loading…
Reference in a new issue