Author data legacy API

This commit is contained in:
Kovid Goyal 2013-07-12 17:27:13 +05:30
parent 598a604853
commit a8033fc610
2 changed files with 22 additions and 0 deletions

View File

@ -312,6 +312,25 @@ class LibraryDatabase(object):
mi = self.new_api.get_metadata(book_id, get_cover=key == 'cover')
return mi.get(key, default)
def authors_sort_strings(self, index, index_is_id=False):
book_id = index if index_is_id else self.data.index_to_id(index)
with self.new_api.read_lock:
af = self.new_api.fields['authors'].table
authors = af.book_col_map.get(book_id, ())
adata = self.new_api._author_data(authors)
return [adata[aid]['sort'] for aid in authors]
def author_sort_from_book(self, index, index_is_id=False):
return ' & '.join(self.authors_sort_strings(index, index_is_id=index_is_id))
def authors_with_sort_strings(self, index, index_is_id=False):
book_id = index if index_is_id else self.data.index_to_id(index)
with self.new_api.read_lock:
af = self.new_api.fields['authors'].table
authors = af.book_col_map.get(book_id, ())
adata = self.new_api._author_data(authors)
return [(aid, adata[aid]['name'], adata[aid]['sort'], adata[aid]['link']) for aid in authors]
# Private interface {{{
def __iter__(self):

View File

@ -172,6 +172,9 @@ class LegacyTest(BaseTest):
'tag_name':[(3,)],
'author_name':[(3,)],
'series_name':[(3,)],
'authors_sort_strings':[(0,), (1,), (2,)],
'author_sort_from_book':[(0,), (1,), (2,)],
'authors_with_sort_strings':[(0,), (1,), (2,)],
}.iteritems():
for a in args:
fmt = lambda x: x