mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
get_*_with_ids() API
This commit is contained in:
parent
9249fd8a3e
commit
ca8f29db0b
@ -389,7 +389,7 @@ class Cache(object):
|
||||
raise ValueError('%s is not a many-one or many-many field' % field)
|
||||
|
||||
@read_api
|
||||
def author_data(self, author_ids):
|
||||
def author_data(self, author_ids=None):
|
||||
'''
|
||||
Return author data as a dictionary with keys: name, sort, link
|
||||
|
||||
|
@ -73,6 +73,12 @@ class LibraryDatabase(object):
|
||||
for func, field in {'all_authors':'authors', 'all_titles':'title', 'all_tags2':'tags', 'all_series':'series', 'all_publishers':'publisher'}.iteritems():
|
||||
setattr(self, func, partial(self.field_id_map, field))
|
||||
self.all_tags = lambda : list(self.all_tag_names())
|
||||
self.get_authors_with_ids = lambda : [[aid, adata['name'], adata['sort'], adata['link']] for aid, adata in self.new_api.author_data().iteritems()]
|
||||
self.get_tags_with_ids = lambda : [[tid, tag] for tid, tag in self.new_api.get_id_map('tags').iteritems()]
|
||||
self.get_series_with_ids = lambda : [[tid, tag] for tid, tag in self.new_api.get_id_map('series').iteritems()]
|
||||
self.get_publishers_with_ids = lambda : [[tid, tag] for tid, tag in self.new_api.get_id_map('publisher').iteritems()]
|
||||
self.get_ratings_with_ids = lambda : [[tid, tag] for tid, tag in self.new_api.get_id_map('rating').iteritems()]
|
||||
self.get_languages_with_ids = lambda : [[tid, tag] for tid, tag in self.new_api.get_id_map('languages').iteritems()]
|
||||
|
||||
for func in (
|
||||
'standard_field_keys', 'custom_field_keys', 'all_field_keys',
|
||||
|
@ -143,12 +143,12 @@ class LegacyTest(BaseTest):
|
||||
'all_tag_names':[()],
|
||||
'all_series_names':[()],
|
||||
'all_publisher_names':[()],
|
||||
'all_authors':[()],
|
||||
'all_tags2':[()],
|
||||
'all_tags':[()],
|
||||
'all_publishers':[()],
|
||||
'all_titles':[()],
|
||||
'all_series':[()],
|
||||
'!all_authors':[()],
|
||||
'!all_tags2':[()],
|
||||
'@all_tags':[()],
|
||||
'!all_publishers':[()],
|
||||
'!all_titles':[()],
|
||||
'!all_series':[()],
|
||||
'standard_field_keys':[()],
|
||||
'all_field_keys':[()],
|
||||
'searchable_fields':[()],
|
||||
@ -156,16 +156,23 @@ class LegacyTest(BaseTest):
|
||||
'metadata_for_field':[('title',), ('tags',)],
|
||||
'sortable_field_keys':[()],
|
||||
'custom_field_keys':[(True,), (False,)],
|
||||
'get_usage_count_by_id':[('authors',), ('tags',), ('series',), ('publisher',), ('#tags',), ('languages',)],
|
||||
'!get_usage_count_by_id':[('authors',), ('tags',), ('series',), ('publisher',), ('#tags',), ('languages',)],
|
||||
'get_field':[(1, 'title'), (2, 'tags'), (0, 'rating'), (1, 'authors'), (2, 'series'), (1, '#tags')],
|
||||
'all_formats':[()],
|
||||
'get_authors_with_ids':[()],
|
||||
'!get_tags_with_ids':[()],
|
||||
'!get_series_with_ids':[()],
|
||||
'!get_publishers_with_ids':[()],
|
||||
'!get_ratings_with_ids':[()],
|
||||
'!get_languages_with_ids':[()],
|
||||
}.iteritems():
|
||||
for a in args:
|
||||
fmt = lambda x: x
|
||||
if meth in {'get_usage_count_by_id', 'all_series', 'all_authors', 'all_tags2', 'all_publishers', 'all_titles'}:
|
||||
fmt = dict
|
||||
elif meth in {'all_tags'}:
|
||||
fmt = frozenset
|
||||
if meth[0] in {'!', '@'}:
|
||||
fmt = {'!':dict, '@':frozenset}[meth[0]]
|
||||
meth = meth[1:]
|
||||
elif meth == 'get_authors_with_ids':
|
||||
fmt = lambda val:{x[0]:tuple(x[1:]) for x in val}
|
||||
self.assertEqual(fmt(getattr(db, meth)(*a)), fmt(getattr(ndb, meth)(*a)),
|
||||
'The method: %s() returned different results for argument %s' % (meth, a))
|
||||
db.close()
|
||||
|
Loading…
x
Reference in New Issue
Block a user