mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Take out sorting change
This commit is contained in:
parent
7e7f0954ce
commit
cbd880e8f7
@ -526,7 +526,7 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
def tags(r, idx=-1):
|
def tags(r, idx=-1):
|
||||||
tags = self.db.data[r][idx]
|
tags = self.db.data[r][idx]
|
||||||
if tags:
|
if tags:
|
||||||
return QVariant(', '.join(tags.split(',')))
|
return QVariant(', '.join(sorted(tags.split(','), key=sort_key)))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def series_type(r, idx=-1, siix=-1):
|
def series_type(r, idx=-1, siix=-1):
|
||||||
@ -577,7 +577,7 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
def text_type(r, mult=False, idx=-1):
|
def text_type(r, mult=False, idx=-1):
|
||||||
text = self.db.data[r][idx]
|
text = self.db.data[r][idx]
|
||||||
if text and mult:
|
if text and mult:
|
||||||
return QVariant(', '.join(text.split('|')))
|
return QVariant(', '.join(sorted(text.split('|'),key=sort_key)))
|
||||||
return QVariant(text)
|
return QVariant(text)
|
||||||
|
|
||||||
def number_type(r, idx=-1):
|
def number_type(r, idx=-1):
|
||||||
|
@ -14,7 +14,6 @@ from calibre.constants import preferred_encoding
|
|||||||
from calibre.library.field_metadata import FieldMetadata
|
from calibre.library.field_metadata import FieldMetadata
|
||||||
from calibre.utils.date import parse_date
|
from calibre.utils.date import parse_date
|
||||||
from calibre.utils.config import tweaks
|
from calibre.utils.config import tweaks
|
||||||
from calibre.utils.icu import sort_key
|
|
||||||
|
|
||||||
class CustomColumns(object):
|
class CustomColumns(object):
|
||||||
|
|
||||||
@ -134,15 +133,7 @@ class CustomColumns(object):
|
|||||||
|
|
||||||
def adapt_bool(x, d):
|
def adapt_bool(x, d):
|
||||||
if isinstance(x, (str, unicode, bytes)):
|
if isinstance(x, (str, unicode, bytes)):
|
||||||
x = x.lower()
|
x = bool(int(x))
|
||||||
if x == 'true':
|
|
||||||
x = True
|
|
||||||
elif x == 'false':
|
|
||||||
x = False
|
|
||||||
elif x == 'none':
|
|
||||||
x = None
|
|
||||||
else:
|
|
||||||
x = bool(int(x))
|
|
||||||
return x
|
return x
|
||||||
|
|
||||||
def adapt_enum(x, d):
|
def adapt_enum(x, d):
|
||||||
@ -151,17 +142,9 @@ class CustomColumns(object):
|
|||||||
v = None
|
v = None
|
||||||
return v
|
return v
|
||||||
|
|
||||||
def adapt_number(x, d):
|
|
||||||
if isinstance(x, (str, unicode, bytes)):
|
|
||||||
if x.lower() == 'none':
|
|
||||||
return None
|
|
||||||
if d['datatype'] == 'int':
|
|
||||||
return int(x)
|
|
||||||
return float(x)
|
|
||||||
|
|
||||||
self.custom_data_adapters = {
|
self.custom_data_adapters = {
|
||||||
'float': adapt_number,
|
'float': lambda x,d : x if x is None else float(x),
|
||||||
'int': adapt_number,
|
'int': lambda x,d : x if x is None else int(x),
|
||||||
'rating':lambda x,d : x if x is None else min(10., max(0., float(x))),
|
'rating':lambda x,d : x if x is None else min(10., max(0., float(x))),
|
||||||
'bool': adapt_bool,
|
'bool': adapt_bool,
|
||||||
'comments': lambda x,d: adapt_text(x, {'is_multiple':False}),
|
'comments': lambda x,d: adapt_text(x, {'is_multiple':False}),
|
||||||
@ -198,8 +181,8 @@ class CustomColumns(object):
|
|||||||
ans = row[self.FIELD_MAP[data['num']]]
|
ans = row[self.FIELD_MAP[data['num']]]
|
||||||
if data['is_multiple'] and data['datatype'] == 'text':
|
if data['is_multiple'] and data['datatype'] == 'text':
|
||||||
ans = ans.split('|') if ans else []
|
ans = ans.split('|') if ans else []
|
||||||
if data['display'].get('sort_alpha', True):
|
if data['display'].get('sort_alpha', False):
|
||||||
ans.sort(key=sort_key)
|
ans.sort(cmp=lambda x,y:cmp(x.lower(), y.lower()))
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
def get_custom_extra(self, idx, label=None, num=None, index_is_id=False):
|
def get_custom_extra(self, idx, label=None, num=None, index_is_id=False):
|
||||||
@ -551,8 +534,8 @@ class CustomColumns(object):
|
|||||||
if data['normalized']:
|
if data['normalized']:
|
||||||
query = '%s.value'
|
query = '%s.value'
|
||||||
if data['is_multiple']:
|
if data['is_multiple']:
|
||||||
query = 'cc_sortconcat(%s.value)'
|
query = 'group_concat(%s.value, "|")'
|
||||||
if not display.get('sort_alpha', True):
|
if not display.get('sort_alpha', False):
|
||||||
query = 'sort_concat(link.id, %s.value)'
|
query = 'sort_concat(link.id, %s.value)'
|
||||||
line = '''(SELECT {query} FROM {lt} AS link INNER JOIN
|
line = '''(SELECT {query} FROM {lt} AS link INNER JOIN
|
||||||
{table} ON(link.value={table}.id) WHERE link.book=books.id)
|
{table} ON(link.value={table}.id) WHERE link.book=books.id)
|
||||||
|
@ -242,7 +242,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
'timestamp',
|
'timestamp',
|
||||||
'(SELECT MAX(uncompressed_size) FROM data WHERE book=books.id) size',
|
'(SELECT MAX(uncompressed_size) FROM data WHERE book=books.id) size',
|
||||||
('rating', 'ratings', 'rating', 'ratings.rating'),
|
('rating', 'ratings', 'rating', 'ratings.rating'),
|
||||||
('tags', 'tags', 'tag', 'tags_sortconcat(name)'),
|
('tags', 'tags', 'tag', 'group_concat(name)'),
|
||||||
'(SELECT text FROM comments WHERE book=books.id) comments',
|
'(SELECT text FROM comments WHERE book=books.id) comments',
|
||||||
('series', 'series', 'series', 'name'),
|
('series', 'series', 'series', 'name'),
|
||||||
('publisher', 'publishers', 'publisher', 'name'),
|
('publisher', 'publishers', 'publisher', 'name'),
|
||||||
|
@ -19,7 +19,7 @@ from calibre.ebooks.metadata import title_sort, author_to_author_sort
|
|||||||
from calibre.utils.date import parse_date, isoformat
|
from calibre.utils.date import parse_date, isoformat
|
||||||
from calibre import isbytestring, force_unicode
|
from calibre import isbytestring, force_unicode
|
||||||
from calibre.constants import iswindows, DEBUG
|
from calibre.constants import iswindows, DEBUG
|
||||||
from calibre.utils.icu import strcmp, sort_key
|
from calibre.utils.icu import strcmp
|
||||||
|
|
||||||
global_lock = RLock()
|
global_lock = RLock()
|
||||||
|
|
||||||
@ -69,25 +69,6 @@ class Concatenate(object):
|
|||||||
return None
|
return None
|
||||||
return self.sep.join(self.ans)
|
return self.sep.join(self.ans)
|
||||||
|
|
||||||
class TagsSortConcatenate(object):
|
|
||||||
'''Sorted string concatenation aggregator for sqlite'''
|
|
||||||
def __init__(self, sep=','):
|
|
||||||
self.sep = sep
|
|
||||||
self.ans = []
|
|
||||||
|
|
||||||
def step(self, value):
|
|
||||||
if value is not None:
|
|
||||||
self.ans.append(value)
|
|
||||||
|
|
||||||
def finalize(self):
|
|
||||||
if not self.ans:
|
|
||||||
return None
|
|
||||||
return self.sep.join(sorted(self.ans, key=sort_key))
|
|
||||||
|
|
||||||
class CcSortConcatenate(TagsSortConcatenate):
|
|
||||||
def __init__(self):
|
|
||||||
TagsSortConcatenate.__init__(self, sep='|')
|
|
||||||
|
|
||||||
class SortedConcatenate(object):
|
class SortedConcatenate(object):
|
||||||
'''String concatenation aggregator for sqlite, sorted by supplied index'''
|
'''String concatenation aggregator for sqlite, sorted by supplied index'''
|
||||||
sep = ','
|
sep = ','
|
||||||
@ -174,8 +155,6 @@ class DBThread(Thread):
|
|||||||
c_ext_loaded = load_c_extensions(self.conn)
|
c_ext_loaded = load_c_extensions(self.conn)
|
||||||
self.conn.row_factory = sqlite.Row if self.row_factory else lambda cursor, row : list(row)
|
self.conn.row_factory = sqlite.Row if self.row_factory else lambda cursor, row : list(row)
|
||||||
self.conn.create_aggregate('concat', 1, Concatenate)
|
self.conn.create_aggregate('concat', 1, Concatenate)
|
||||||
self.conn.create_aggregate('tags_sortconcat', 1, TagsSortConcatenate)
|
|
||||||
self.conn.create_aggregate('cc_sortconcat', 1, CcSortConcatenate)
|
|
||||||
if not c_ext_loaded:
|
if not c_ext_loaded:
|
||||||
self.conn.create_aggregate('sortconcat', 2, SortedConcatenate)
|
self.conn.create_aggregate('sortconcat', 2, SortedConcatenate)
|
||||||
self.conn.create_aggregate('sort_concat', 2, SafeSortedConcatenate)
|
self.conn.create_aggregate('sort_concat', 2, SafeSortedConcatenate)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user