mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Ensure numberic sort keys are 0 is the value is None or an empty string
This commit is contained in:
parent
4bb557ec41
commit
9bb6e83b68
@ -25,6 +25,10 @@ def bool_sort_key(bools_are_tristate):
|
||||
return (lambda x:{True: 1, False: 2, None: 3}.get(x, 3)) if bools_are_tristate else lambda x:{True: 1, False: 2, None: 2}.get(x, 2)
|
||||
|
||||
|
||||
def numeric_sort_key(x):
|
||||
return x or 0
|
||||
|
||||
|
||||
IDENTITY = lambda x: x
|
||||
|
||||
|
||||
@ -56,6 +60,7 @@ class Field(object):
|
||||
|
||||
if dt in {'int', 'float', 'rating'}:
|
||||
self._default_sort_key = 0
|
||||
self._sort_key = numeric_sort_key
|
||||
elif dt == 'bool':
|
||||
self._default_sort_key = None
|
||||
self._sort_key = bool_sort_key(bools_are_tristate)
|
||||
|
Loading…
x
Reference in New Issue
Block a user