Improvements to the new tag browser views.

This commit is contained in:
Charles Haley 2010-06-14 10:30:13 +01:00
parent f7b7ff0c5f
commit 34312daed3
4 changed files with 25 additions and 29 deletions

View File

@ -138,7 +138,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
name,
(SELECT COUNT(books_tags_link.id) FROM books_tags_link WHERE tag=x.id) count,
(0) as avg_rating,
(null) as sort
name as sort
FROM tags as x WHERE name!="{0}" AND id IN
(SELECT DISTINCT tag FROM books_tags_link WHERE book IN
(SELECT DISTINCT book FROM books_tags_link WHERE tag IN
@ -151,7 +151,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
name,
(SELECT COUNT(books_tags_link.id) FROM books_tags_link WHERE tag=x.id and books_list_filter(book)) count,
(0) as avg_rating,
(null) as sort
name as sort
FROM tags as x WHERE name!="{0}" AND id IN
(SELECT DISTINCT tag FROM books_tags_link WHERE book IN
(SELECT DISTINCT book FROM books_tags_link WHERE tag IN
@ -714,9 +714,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
if sort_on_count:
query += ' ORDER BY count DESC'
else:
if 'category_sort' in cat:
cn = cat['category_sort']
query += ' ORDER BY {0} ASC'.format(cn)
query += ' ORDER BY sort ASC'
data = self.conn.get(query)
# 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']
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)
formatter = (lambda x:u'\u2605'*int(round(x/2.)))
elif category == 'authors':
@ -748,13 +747,6 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
avg=r[3], sort=r[4],
icon=icon, tooltip=tooltip)
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
# use a view, but is computed dynamically

View File

@ -44,9 +44,12 @@ class FieldMetadata(dict):
is_category: is a tag browser category. If true, then:
table: name of the db table used to construct item list
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
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
appear in the tags pane.
@ -66,17 +69,18 @@ class FieldMetadata(dict):
('authors', {'table':'authors',
'column':'name',
'link_column':'author',
'category_sort':'sort',
'datatype':'text',
'is_multiple':',',
'kind':'field',
'name':_('Authors'),
'search_terms':['authors', 'author'],
'is_custom':False,
'is_category':True,
'category_sort':'sort'}),
'is_category':True}),
('series', {'table':'series',
'column':'name',
'link_column':'series',
'category_sort':'(title_sort(name))',
'datatype':'text',
'is_multiple':None,
'kind':'field',
@ -96,6 +100,7 @@ class FieldMetadata(dict):
('publisher', {'table':'publishers',
'column':'name',
'link_column':'publisher',
'category_sort':'name',
'datatype':'text',
'is_multiple':None,
'kind':'field',
@ -106,6 +111,7 @@ class FieldMetadata(dict):
('rating', {'table':'ratings',
'column':'rating',
'link_column':'rating',
'category_sort':'rating',
'datatype':'rating',
'is_multiple':None,
'kind':'field',
@ -115,6 +121,7 @@ class FieldMetadata(dict):
'is_category':True}),
('news', {'table':'news',
'column':'name',
'category_sort':'name',
'datatype':None,
'is_multiple':None,
'kind':'category',
@ -125,6 +132,7 @@ class FieldMetadata(dict):
('tags', {'table':'tags',
'column':'name',
'link_column': 'tag',
'category_sort':'name',
'datatype':'text',
'is_multiple':',',
'kind':'field',
@ -375,7 +383,7 @@ class FieldMetadata(dict):
'search_terms':[key], 'label':label,
'colnum':colnum, 'display':display,
'is_custom':True, 'is_category':is_category,
'link_column':'value',
'link_column':'value','category_sort':'value',
'is_editable': is_editable,}
self._add_search_terms_to_map(key, [key])
self.custom_label_to_key_map[label] = key

View File

@ -361,15 +361,11 @@ class SchemaUpgrade(object):
'''.format(lt=link_table_name, table=table_name)
self.conn.executescript(script)
STANDARD_TAG_BROWSER_TABLES = [
('authors', 'author', 'name', 'sort'),
('publishers', 'publisher', 'name', 'name'),
('ratings', 'rating', 'rating', 'rating'),
('series', 'series', 'name', 'name'),
('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)
for field in self.field_metadata.itervalues():
if field['is_category'] and not field['is_custom'] and 'link_column' in field:
print field['table']
create_std_tag_browser_view(field['table'], field['link_column'],
field['column'], field['category_sort'])
db_tables = self.conn.get('''SELECT name FROM sqlite_master
WHERE type='table'

View File

@ -116,10 +116,10 @@ class DBThread(Thread):
self.conn.create_aggregate('concat', 1, Concatenate)
self.conn.create_aggregate('sortconcat', 2, SortedConcatenate)
self.conn.create_aggregate('sort_concat', 2, SafeSortedConcatenate)
if tweaks['title_series_sorting'] == 'library_order':
self.conn.create_function('title_sort', 1, title_sort)
else:
if tweaks['title_series_sorting'] == 'strictly_alphabetic':
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,
lambda x: author_to_author_sort(x.replace('|', ',')))
self.conn.create_function('uuid4', 0, lambda : str(uuid.uuid4()))