mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Implement formats category
This commit is contained in:
parent
c7e8509e10
commit
dee27d1a84
@ -53,8 +53,8 @@ class Tag(object):
|
||||
|
||||
def find_categories(field_metadata):
|
||||
for category, cat in field_metadata.iteritems():
|
||||
if (cat['is_category'] and cat['kind'] not in { 'user', 'search' } and
|
||||
category not in {'news', 'formats'}):
|
||||
if (cat['is_category'] and cat['kind'] not in {'user', 'search'} and
|
||||
category != 'news'):
|
||||
yield (category, cat['is_multiple'].get('cache_to_list', None), False)
|
||||
elif (cat['datatype'] == 'composite' and
|
||||
cat['display'].get('make_category', False)):
|
||||
@ -63,7 +63,7 @@ def find_categories(field_metadata):
|
||||
def create_tag_class(category, fm, icon_map):
|
||||
cat = fm[category]
|
||||
icon = None
|
||||
tooltip = None if category == 'identifiers' else ('(' + category + ')')
|
||||
tooltip = None if category in {'formats', 'identifiers'} else ('(' + category + ')')
|
||||
label = fm.key_to_label(category)
|
||||
if icon_map:
|
||||
if not fm.is_custom_field(category):
|
||||
@ -72,7 +72,8 @@ def create_tag_class(category, fm, icon_map):
|
||||
else:
|
||||
icon = icon_map['custom:']
|
||||
icon_map[category] = icon
|
||||
is_editable = category not in { 'news', 'rating', 'languages' }
|
||||
is_editable = category not in {'news', 'rating', 'languages', 'formats',
|
||||
'identifiers'}
|
||||
|
||||
if (tweaks['categories_use_field_for_author_name'] == 'author_sort' and
|
||||
(category == 'authors' or
|
||||
@ -87,7 +88,6 @@ def create_tag_class(category, fm, icon_map):
|
||||
tooltip=tooltip, is_editable=is_editable,
|
||||
category=category)
|
||||
|
||||
|
||||
def get_categories(dbcache, sort='name', book_ids=None, icon_map=None):
|
||||
if icon_map is not None and type(icon_map) != TagsIcons:
|
||||
raise TypeError('icon_map passed to get_categories must be of type TagIcons')
|
||||
|
@ -362,8 +362,7 @@ class IdentifiersField(ManyToManyField):
|
||||
if book_ids is not None:
|
||||
item_book_ids = item_book_ids.intersection(book_ids)
|
||||
if item_book_ids:
|
||||
name = id_key
|
||||
c = tag_class(name, id_set=item_book_ids, count=len(item_book_ids))
|
||||
c = tag_class(id_key, id_set=item_book_ids, count=len(item_book_ids))
|
||||
ans.append(c)
|
||||
return ans
|
||||
|
||||
@ -398,6 +397,17 @@ class FormatsField(ManyToManyField):
|
||||
for val, book_ids in val_map.iteritems():
|
||||
yield val, book_ids
|
||||
|
||||
def get_categories(self, tag_class, book_rating_map, lang_map, book_ids=None):
|
||||
ans = []
|
||||
|
||||
for fmt, item_book_ids in self.table.col_book_map.iteritems():
|
||||
if book_ids is not None:
|
||||
item_book_ids = item_book_ids.intersection(book_ids)
|
||||
if item_book_ids:
|
||||
c = tag_class(fmt, id_set=item_book_ids, count=len(item_book_ids))
|
||||
ans.append(c)
|
||||
return ans
|
||||
|
||||
class SeriesField(ManyToOneField):
|
||||
|
||||
def sort_key_for_series(self, book_id, lang_map, series_sort_order):
|
||||
|
@ -42,6 +42,7 @@ class BaseTest(unittest.TestCase):
|
||||
if attr == 'format_metadata': continue # TODO: Not implemented yet
|
||||
attr1, attr2 = getattr(mi1, attr), getattr(mi2, attr)
|
||||
if attr == 'formats':
|
||||
continue # TODO: Not implemented yet
|
||||
attr1, attr2 = map(lambda x:tuple(x) if x else (), (attr1, attr2))
|
||||
self.assertEqual(attr1, attr2,
|
||||
'%s not the same: %r != %r'%(attr, attr1, attr2))
|
||||
|
@ -241,6 +241,18 @@ class ReadingTest(BaseTest):
|
||||
|
||||
# }}}
|
||||
|
||||
def test_get_categories(self): # {{{
|
||||
'Check that get_categories() returns the same data for both backends'
|
||||
from calibre.library.database2 import LibraryDatabase2
|
||||
old = LibraryDatabase2(self.library_path)
|
||||
old_categories = old.get_categories()
|
||||
cache = self.init_cache(self.library_path)
|
||||
import pprint
|
||||
pprint.pprint(old_categories)
|
||||
pprint.pprint(cache.get_categories())
|
||||
|
||||
# }}}
|
||||
|
||||
def tests():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(ReadingTest)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user