mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Refactor the author data api for multiple authors
This commit is contained in:
parent
abf3bed75b
commit
9249fd8a3e
@ -161,7 +161,8 @@ class Cache(object):
|
|||||||
def _get_metadata(self, book_id, get_user_categories=True): # {{{
|
def _get_metadata(self, book_id, get_user_categories=True): # {{{
|
||||||
mi = Metadata(None, template_cache=self.formatter_template_cache)
|
mi = Metadata(None, template_cache=self.formatter_template_cache)
|
||||||
author_ids = self._field_ids_for('authors', book_id)
|
author_ids = self._field_ids_for('authors', book_id)
|
||||||
aut_list = [self._author_data(i) for i in author_ids]
|
adata = self._author_data(author_ids)
|
||||||
|
aut_list = [adata[i] for i in author_ids]
|
||||||
aum = []
|
aum = []
|
||||||
aus = {}
|
aus = {}
|
||||||
aul = {}
|
aul = {}
|
||||||
@ -388,17 +389,17 @@ class Cache(object):
|
|||||||
raise ValueError('%s is not a many-one or many-many field' % field)
|
raise ValueError('%s is not a many-one or many-many field' % field)
|
||||||
|
|
||||||
@read_api
|
@read_api
|
||||||
def author_data(self, author_id):
|
def author_data(self, author_ids):
|
||||||
'''
|
'''
|
||||||
Return author data as a dictionary with keys: name, sort, link
|
Return author data as a dictionary with keys: name, sort, link
|
||||||
|
|
||||||
If no author with the specified id is found an empty dictionary is
|
If no authors with the specified ids are found an empty dictionary is
|
||||||
returned.
|
returned. If author_ids is None, data for all authors is returned.
|
||||||
'''
|
'''
|
||||||
try:
|
af = self.fields['authors']
|
||||||
return self.fields['authors'].author_data(author_id)
|
if author_ids is None:
|
||||||
except (KeyError, IndexError):
|
author_ids = tuple(af.table.id_map)
|
||||||
return {}
|
return {aid:af.author_data(aid) for aid in author_ids if aid in af.table.id_map}
|
||||||
|
|
||||||
@read_api
|
@read_api
|
||||||
def format_metadata(self, book_id, fmt, allow_cache=True):
|
def format_metadata(self, book_id, fmt, allow_cache=True):
|
||||||
|
@ -243,6 +243,8 @@ class LegacyTest(BaseTest):
|
|||||||
'_set_title', '_set_custom', '_update_author_in_cache',
|
'_set_title', '_set_custom', '_update_author_in_cache',
|
||||||
# Feeds are now stored in the config folder
|
# Feeds are now stored in the config folder
|
||||||
'get_feeds', 'get_feed', 'update_feed', 'remove_feeds', 'add_feed', 'set_feeds',
|
'get_feeds', 'get_feed', 'update_feed', 'remove_feeds', 'add_feed', 'set_feeds',
|
||||||
|
# Obsolete/broken methods
|
||||||
|
'author_id', # replaced by get_author_id
|
||||||
}
|
}
|
||||||
SKIP_ARGSPEC = {
|
SKIP_ARGSPEC = {
|
||||||
'__init__', 'get_next_series_num_for', 'has_book', 'author_sort_from_authors', 'all_tags',
|
'__init__', 'get_next_series_num_for', 'has_book', 'author_sort_from_authors', 'all_tags',
|
||||||
|
@ -189,10 +189,8 @@ class View(object):
|
|||||||
id_ = idx if index_is_id else self.index_to_id(idx)
|
id_ = idx if index_is_id else self.index_to_id(idx)
|
||||||
with self.cache.read_lock:
|
with self.cache.read_lock:
|
||||||
ids = self.cache._field_ids_for('authors', id_)
|
ids = self.cache._field_ids_for('authors', id_)
|
||||||
ans = []
|
adata = self.cache._author_data(ids)
|
||||||
for id_ in ids:
|
ans = [':::'.join((adata[aid]['name'], adata[aid]['sort'], adata[aid]['link'])) for aid in ids if aid in adata]
|
||||||
data = self.cache._author_data(id_)
|
|
||||||
ans.append(':::'.join((data['name'], data['sort'], data['link'])))
|
|
||||||
return ':#:'.join(ans) if ans else default_value
|
return ':#:'.join(ans) if ans else default_value
|
||||||
|
|
||||||
def multisort(self, fields=[], subsort=False, only_ids=None):
|
def multisort(self, fields=[], subsort=False, only_ids=None):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user