mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
API to get item name from item id
This commit is contained in:
parent
d80f36ef28
commit
71e27433ec
@ -388,6 +388,10 @@ class Cache(object):
|
|||||||
return self.fields[field].table.book_col_map.copy()
|
return self.fields[field].table.book_col_map.copy()
|
||||||
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
|
||||||
|
def get_item_name(self, field, item_id):
|
||||||
|
return self.fields[field].table.id_map[item_id]
|
||||||
|
|
||||||
@read_api
|
@read_api
|
||||||
def author_data(self, author_ids=None):
|
def author_data(self, author_ids=None):
|
||||||
'''
|
'''
|
||||||
|
@ -90,6 +90,13 @@ class LibraryDatabase(object):
|
|||||||
return func
|
return func
|
||||||
setattr(self, 'get_%s_with_ids' % field,
|
setattr(self, 'get_%s_with_ids' % field,
|
||||||
MT(getter(field)))
|
MT(getter(field)))
|
||||||
|
for field in ('author', 'tag', 'series'):
|
||||||
|
def getter(field):
|
||||||
|
field = field if field == 'series' else (field+'s')
|
||||||
|
def func(self, item_id):
|
||||||
|
return self.new_api.get_item_name(field, item_id)
|
||||||
|
return func
|
||||||
|
setattr(self, '%s_name' % field, MT(getter(field)))
|
||||||
|
|
||||||
# Legacy field API
|
# Legacy field API
|
||||||
for func in (
|
for func in (
|
||||||
|
@ -32,7 +32,9 @@ class ET(object):
|
|||||||
return newres
|
return newres
|
||||||
|
|
||||||
def compare_argspecs(old, new, attr):
|
def compare_argspecs(old, new, attr):
|
||||||
ok = len(old.args) == len(new.args) and len(old.defaults or ()) == len(new.defaults or ()) and old.args[-len(old.defaults or ()):] == new.args[-len(new.defaults or ()):] # noqa
|
num = len(old.defaults or ())
|
||||||
|
|
||||||
|
ok = len(old.args) == len(new.args) and old.defaults == new.defaults and (num == 0 or old.args[-num:] == new.args[-num:])
|
||||||
if not ok:
|
if not ok:
|
||||||
raise AssertionError('The argspec for %s does not match. %r != %r' % (attr, old, new))
|
raise AssertionError('The argspec for %s does not match. %r != %r' % (attr, old, new))
|
||||||
|
|
||||||
@ -165,6 +167,9 @@ class LegacyTest(BaseTest):
|
|||||||
'!get_publishers_with_ids':[()],
|
'!get_publishers_with_ids':[()],
|
||||||
'!get_ratings_with_ids':[()],
|
'!get_ratings_with_ids':[()],
|
||||||
'!get_languages_with_ids':[()],
|
'!get_languages_with_ids':[()],
|
||||||
|
'tag_name':[(3,)],
|
||||||
|
'author_name':[(3,)],
|
||||||
|
'series_name':[(3,)],
|
||||||
}.iteritems():
|
}.iteritems():
|
||||||
for a in args:
|
for a in args:
|
||||||
fmt = lambda x: x
|
fmt = lambda x: x
|
||||||
|
Loading…
x
Reference in New Issue
Block a user