mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Tentative {virtual_libraries} template support
This should allow the use of {virtual_libraries} in custom column templates, with good performance, thanks to search caching.
This commit is contained in:
parent
70f1dbb832
commit
cbf2bb0c4e
@ -1620,6 +1620,18 @@ class Cache(object):
|
|||||||
if cover and os.path.exists(cover):
|
if cover and os.path.exists(cover):
|
||||||
self._set_field('cover', {book_id:1})
|
self._set_field('cover', {book_id:1})
|
||||||
self.backend.restore_book(book_id, path, formats)
|
self.backend.restore_book(book_id, path, formats)
|
||||||
|
|
||||||
|
@read_api
|
||||||
|
def virtual_libraries_for_books(self, book_ids):
|
||||||
|
libraries = tuple(self._pref('virtual_libraries', {}).iterkeys())
|
||||||
|
ans = {book_id:[] for book_id in book_ids}
|
||||||
|
for lib in libraries:
|
||||||
|
books = self._search(lib) # We deliberately dont use book_ids as we want to use the search cache
|
||||||
|
for book in book_ids:
|
||||||
|
if book in books:
|
||||||
|
ans[book].append(lib)
|
||||||
|
return {k:tuple(sorted(v, key=sort_key)) for k, v in book_ids}
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
class SortKey(object): # {{{
|
class SortKey(object): # {{{
|
||||||
|
@ -231,6 +231,15 @@ def composite_getter(mi, field, metadata, book_id, cache, formatter, template_ca
|
|||||||
template_cache=template_cache).strip()
|
template_cache=template_cache).strip()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
def virtual_libraries_getter(dbref, book_id, cache):
|
||||||
|
try:
|
||||||
|
return cache[field]
|
||||||
|
except KeyError:
|
||||||
|
db = dbref()
|
||||||
|
vls = db.virtual_libraries_for_books((book_id,))[book_id]
|
||||||
|
ret = cache[field] = ', '.join(vls)
|
||||||
|
return ret
|
||||||
|
|
||||||
getters = {
|
getters = {
|
||||||
'title':simple_getter('title', _('Unknown')),
|
'title':simple_getter('title', _('Unknown')),
|
||||||
'title_sort':simple_getter('sort', _('Unknown')),
|
'title_sort':simple_getter('sort', _('Unknown')),
|
||||||
@ -247,6 +256,7 @@ getters = {
|
|||||||
'series_index':series_index_getter(),
|
'series_index':series_index_getter(),
|
||||||
'application_id':lambda x, book_id, y: book_id,
|
'application_id':lambda x, book_id, y: book_id,
|
||||||
'id':lambda x, book_id, y: book_id,
|
'id':lambda x, book_id, y: book_id,
|
||||||
|
'virtual_libraries':virtual_libraries_getter,
|
||||||
}
|
}
|
||||||
|
|
||||||
for field in ('comments', 'publisher', 'identifiers', 'series', 'rating'):
|
for field in ('comments', 'publisher', 'identifiers', 'series', 'rating'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user