mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Improvements to the new tag browser views.
This commit is contained in:
parent
f7b7ff0c5f
commit
34312daed3
@ -138,7 +138,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
name,
|
name,
|
||||||
(SELECT COUNT(books_tags_link.id) FROM books_tags_link WHERE tag=x.id) count,
|
(SELECT COUNT(books_tags_link.id) FROM books_tags_link WHERE tag=x.id) count,
|
||||||
(0) as avg_rating,
|
(0) as avg_rating,
|
||||||
(null) as sort
|
name as sort
|
||||||
FROM tags as x WHERE name!="{0}" AND id IN
|
FROM tags as x WHERE name!="{0}" AND id IN
|
||||||
(SELECT DISTINCT tag FROM books_tags_link WHERE book IN
|
(SELECT DISTINCT tag FROM books_tags_link WHERE book IN
|
||||||
(SELECT DISTINCT book FROM books_tags_link WHERE tag IN
|
(SELECT DISTINCT book FROM books_tags_link WHERE tag IN
|
||||||
@ -151,7 +151,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
name,
|
name,
|
||||||
(SELECT COUNT(books_tags_link.id) FROM books_tags_link WHERE tag=x.id and books_list_filter(book)) count,
|
(SELECT COUNT(books_tags_link.id) FROM books_tags_link WHERE tag=x.id and books_list_filter(book)) count,
|
||||||
(0) as avg_rating,
|
(0) as avg_rating,
|
||||||
(null) as sort
|
name as sort
|
||||||
FROM tags as x WHERE name!="{0}" AND id IN
|
FROM tags as x WHERE name!="{0}" AND id IN
|
||||||
(SELECT DISTINCT tag FROM books_tags_link WHERE book IN
|
(SELECT DISTINCT tag FROM books_tags_link WHERE book IN
|
||||||
(SELECT DISTINCT book FROM books_tags_link WHERE tag IN
|
(SELECT DISTINCT book FROM books_tags_link WHERE tag IN
|
||||||
@ -714,9 +714,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
if sort_on_count:
|
if sort_on_count:
|
||||||
query += ' ORDER BY count DESC'
|
query += ' ORDER BY count DESC'
|
||||||
else:
|
else:
|
||||||
if 'category_sort' in cat:
|
query += ' ORDER BY sort ASC'
|
||||||
cn = cat['category_sort']
|
|
||||||
query += ' ORDER BY {0} ASC'.format(cn)
|
|
||||||
data = self.conn.get(query)
|
data = self.conn.get(query)
|
||||||
|
|
||||||
# icon_map is not None if get_categories is to store an icon and
|
# icon_map is not None if get_categories is to store an icon and
|
||||||
@ -734,6 +732,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
|
|
||||||
datatype = cat['datatype']
|
datatype = cat['datatype']
|
||||||
if datatype == 'rating':
|
if datatype == 'rating':
|
||||||
|
# eliminate the zero ratings line as well as count == 0
|
||||||
item_not_zero_func = (lambda x: x[1] > 0 and x[2] > 0)
|
item_not_zero_func = (lambda x: x[1] > 0 and x[2] > 0)
|
||||||
formatter = (lambda x:u'\u2605'*int(round(x/2.)))
|
formatter = (lambda x:u'\u2605'*int(round(x/2.)))
|
||||||
elif category == 'authors':
|
elif category == 'authors':
|
||||||
@ -748,13 +747,6 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
avg=r[3], sort=r[4],
|
avg=r[3], sort=r[4],
|
||||||
icon=icon, tooltip=tooltip)
|
icon=icon, tooltip=tooltip)
|
||||||
for r in data if item_not_zero_func(r)]
|
for r in data if item_not_zero_func(r)]
|
||||||
if category == 'series' and not sort_on_count:
|
|
||||||
if tweaks['title_series_sorting'] == 'library_order':
|
|
||||||
ts = lambda x: title_sort(x)
|
|
||||||
else:
|
|
||||||
ts = lambda x:x
|
|
||||||
categories[category].sort(cmp=lambda x,y:cmp(ts(x.name).lower(),
|
|
||||||
ts(y.name).lower()))
|
|
||||||
|
|
||||||
# We delayed computing the standard formats category because it does not
|
# We delayed computing the standard formats category because it does not
|
||||||
# use a view, but is computed dynamically
|
# use a view, but is computed dynamically
|
||||||
|
@ -44,9 +44,12 @@ class FieldMetadata(dict):
|
|||||||
is_category: is a tag browser category. If true, then:
|
is_category: is a tag browser category. If true, then:
|
||||||
table: name of the db table used to construct item list
|
table: name of the db table used to construct item list
|
||||||
column: name of the column in the normalized table to join on
|
column: name of the column in the normalized table to join on
|
||||||
link_column: name of the column in the connection table to join on
|
link_column: name of the column in the connection table to join on. This
|
||||||
|
key should not be present if there is no link table
|
||||||
|
category_sort: the field in the normalized table to sort on. This
|
||||||
|
key must be present if is_category is True
|
||||||
If these are None, then the category constructor must know how
|
If these are None, then the category constructor must know how
|
||||||
to build the item list (e.g., formats).
|
to build the item list (e.g., formats, news).
|
||||||
The order below is the order that the categories will
|
The order below is the order that the categories will
|
||||||
appear in the tags pane.
|
appear in the tags pane.
|
||||||
|
|
||||||
@ -66,17 +69,18 @@ class FieldMetadata(dict):
|
|||||||
('authors', {'table':'authors',
|
('authors', {'table':'authors',
|
||||||
'column':'name',
|
'column':'name',
|
||||||
'link_column':'author',
|
'link_column':'author',
|
||||||
|
'category_sort':'sort',
|
||||||
'datatype':'text',
|
'datatype':'text',
|
||||||
'is_multiple':',',
|
'is_multiple':',',
|
||||||
'kind':'field',
|
'kind':'field',
|
||||||
'name':_('Authors'),
|
'name':_('Authors'),
|
||||||
'search_terms':['authors', 'author'],
|
'search_terms':['authors', 'author'],
|
||||||
'is_custom':False,
|
'is_custom':False,
|
||||||
'is_category':True,
|
'is_category':True}),
|
||||||
'category_sort':'sort'}),
|
|
||||||
('series', {'table':'series',
|
('series', {'table':'series',
|
||||||
'column':'name',
|
'column':'name',
|
||||||
'link_column':'series',
|
'link_column':'series',
|
||||||
|
'category_sort':'(title_sort(name))',
|
||||||
'datatype':'text',
|
'datatype':'text',
|
||||||
'is_multiple':None,
|
'is_multiple':None,
|
||||||
'kind':'field',
|
'kind':'field',
|
||||||
@ -96,6 +100,7 @@ class FieldMetadata(dict):
|
|||||||
('publisher', {'table':'publishers',
|
('publisher', {'table':'publishers',
|
||||||
'column':'name',
|
'column':'name',
|
||||||
'link_column':'publisher',
|
'link_column':'publisher',
|
||||||
|
'category_sort':'name',
|
||||||
'datatype':'text',
|
'datatype':'text',
|
||||||
'is_multiple':None,
|
'is_multiple':None,
|
||||||
'kind':'field',
|
'kind':'field',
|
||||||
@ -106,6 +111,7 @@ class FieldMetadata(dict):
|
|||||||
('rating', {'table':'ratings',
|
('rating', {'table':'ratings',
|
||||||
'column':'rating',
|
'column':'rating',
|
||||||
'link_column':'rating',
|
'link_column':'rating',
|
||||||
|
'category_sort':'rating',
|
||||||
'datatype':'rating',
|
'datatype':'rating',
|
||||||
'is_multiple':None,
|
'is_multiple':None,
|
||||||
'kind':'field',
|
'kind':'field',
|
||||||
@ -115,6 +121,7 @@ class FieldMetadata(dict):
|
|||||||
'is_category':True}),
|
'is_category':True}),
|
||||||
('news', {'table':'news',
|
('news', {'table':'news',
|
||||||
'column':'name',
|
'column':'name',
|
||||||
|
'category_sort':'name',
|
||||||
'datatype':None,
|
'datatype':None,
|
||||||
'is_multiple':None,
|
'is_multiple':None,
|
||||||
'kind':'category',
|
'kind':'category',
|
||||||
@ -125,6 +132,7 @@ class FieldMetadata(dict):
|
|||||||
('tags', {'table':'tags',
|
('tags', {'table':'tags',
|
||||||
'column':'name',
|
'column':'name',
|
||||||
'link_column': 'tag',
|
'link_column': 'tag',
|
||||||
|
'category_sort':'name',
|
||||||
'datatype':'text',
|
'datatype':'text',
|
||||||
'is_multiple':',',
|
'is_multiple':',',
|
||||||
'kind':'field',
|
'kind':'field',
|
||||||
@ -375,7 +383,7 @@ class FieldMetadata(dict):
|
|||||||
'search_terms':[key], 'label':label,
|
'search_terms':[key], 'label':label,
|
||||||
'colnum':colnum, 'display':display,
|
'colnum':colnum, 'display':display,
|
||||||
'is_custom':True, 'is_category':is_category,
|
'is_custom':True, 'is_category':is_category,
|
||||||
'link_column':'value',
|
'link_column':'value','category_sort':'value',
|
||||||
'is_editable': is_editable,}
|
'is_editable': is_editable,}
|
||||||
self._add_search_terms_to_map(key, [key])
|
self._add_search_terms_to_map(key, [key])
|
||||||
self.custom_label_to_key_map[label] = key
|
self.custom_label_to_key_map[label] = key
|
||||||
|
@ -361,15 +361,11 @@ class SchemaUpgrade(object):
|
|||||||
'''.format(lt=link_table_name, table=table_name)
|
'''.format(lt=link_table_name, table=table_name)
|
||||||
self.conn.executescript(script)
|
self.conn.executescript(script)
|
||||||
|
|
||||||
STANDARD_TAG_BROWSER_TABLES = [
|
for field in self.field_metadata.itervalues():
|
||||||
('authors', 'author', 'name', 'sort'),
|
if field['is_category'] and not field['is_custom'] and 'link_column' in field:
|
||||||
('publishers', 'publisher', 'name', 'name'),
|
print field['table']
|
||||||
('ratings', 'rating', 'rating', 'rating'),
|
create_std_tag_browser_view(field['table'], field['link_column'],
|
||||||
('series', 'series', 'name', 'name'),
|
field['column'], field['category_sort'])
|
||||||
('tags', 'tag', 'name', 'name'),
|
|
||||||
]
|
|
||||||
for table, column, view_column, sort_column in STANDARD_TAG_BROWSER_TABLES:
|
|
||||||
create_std_tag_browser_view(table, column, view_column, sort_column)
|
|
||||||
|
|
||||||
db_tables = self.conn.get('''SELECT name FROM sqlite_master
|
db_tables = self.conn.get('''SELECT name FROM sqlite_master
|
||||||
WHERE type='table'
|
WHERE type='table'
|
||||||
|
@ -116,10 +116,10 @@ class DBThread(Thread):
|
|||||||
self.conn.create_aggregate('concat', 1, Concatenate)
|
self.conn.create_aggregate('concat', 1, Concatenate)
|
||||||
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)
|
||||||
if tweaks['title_series_sorting'] == 'library_order':
|
if tweaks['title_series_sorting'] == 'strictly_alphabetic':
|
||||||
self.conn.create_function('title_sort', 1, title_sort)
|
|
||||||
else:
|
|
||||||
self.conn.create_function('title_sort', 1, lambda x:x)
|
self.conn.create_function('title_sort', 1, lambda x:x)
|
||||||
|
else:
|
||||||
|
self.conn.create_function('title_sort', 1, title_sort)
|
||||||
self.conn.create_function('author_to_author_sort', 1,
|
self.conn.create_function('author_to_author_sort', 1,
|
||||||
lambda x: author_to_author_sort(x.replace('|', ',')))
|
lambda x: author_to_author_sort(x.replace('|', ',')))
|
||||||
self.conn.create_function('uuid4', 0, lambda : str(uuid.uuid4()))
|
self.conn.create_function('uuid4', 0, lambda : str(uuid.uuid4()))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user