mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Add the news category
This commit is contained in:
parent
f0c69471fc
commit
db50889a80
@ -53,8 +53,7 @@ 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 != 'news'):
|
||||
if (cat['is_category'] and cat['kind'] not in {'user', 'search'}):
|
||||
yield (category, cat['is_multiple'].get('cache_to_list', None), False)
|
||||
elif (cat['datatype'] == 'composite' and
|
||||
cat['display'].get('make_category', False)):
|
||||
@ -102,8 +101,11 @@ def get_categories(dbcache, sort='name', book_ids=None, icon_map=None):
|
||||
book_ids = frozenset(book_ids) if book_ids else book_ids
|
||||
for category, is_multiple, is_composite in find_categories(fm):
|
||||
tag_class = create_tag_class(category, fm, icon_map)
|
||||
cats = dbcache.fields[category].get_categories(
|
||||
tag_class, book_rating_map, lang_map, book_ids)
|
||||
if category == 'news':
|
||||
cats = dbcache.fields['tags'].get_news_category(tag_class, book_ids)
|
||||
else:
|
||||
cats = dbcache.fields[category].get_categories(
|
||||
tag_class, book_rating_map, lang_map, book_ids)
|
||||
if sort == 'popularity':
|
||||
key=attrgetter('count')
|
||||
elif sort == 'rating':
|
||||
|
@ -441,6 +441,34 @@ class SeriesField(ManyToOneField):
|
||||
val = self.table.id_map[item_id]
|
||||
return title_sort(val, order=tss, lang=lang)
|
||||
|
||||
class TagsField(ManyToManyField):
|
||||
|
||||
def get_news_category(self, tag_class, book_ids=None):
|
||||
news_id = None
|
||||
ans = []
|
||||
for item_id, val in self.table.id_map.iteritems():
|
||||
if val == _('News'):
|
||||
news_id = item_id
|
||||
break
|
||||
if news_id is None:
|
||||
return ans
|
||||
|
||||
news_books = self.table.col_book_map[news_id]
|
||||
if book_ids is not None:
|
||||
news_books = news_books.intersection(book_ids)
|
||||
if not news_books:
|
||||
return ans
|
||||
for item_id, item_book_ids in self.table.col_book_map.iteritems():
|
||||
item_book_ids = item_book_ids.intersection(news_books)
|
||||
if item_book_ids:
|
||||
name = self.category_formatter(self.table.id_map[item_id])
|
||||
if name == _('News'):
|
||||
continue
|
||||
c = tag_class(name, id=item_id, sort=name,
|
||||
id_set=item_book_ids, count=len(item_book_ids))
|
||||
ans.append(c)
|
||||
return ans
|
||||
|
||||
def create_field(name, table):
|
||||
cls = {
|
||||
ONE_ONE : OneToOneField,
|
||||
@ -455,6 +483,8 @@ def create_field(name, table):
|
||||
cls = FormatsField
|
||||
elif name == 'identifiers':
|
||||
cls = IdentifiersField
|
||||
elif name == 'tags':
|
||||
cls = TagsField
|
||||
elif table.metadata['datatype'] == 'composite':
|
||||
cls = CompositeField
|
||||
elif table.metadata['datatype'] == 'series':
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user