From 33c8c74e2d709240d400edc0d8b08058403e5296 Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Fri, 10 Nov 2017 15:16:10 +0100 Subject: [PATCH] cover images in filter API --- src/api/handlers.py | 7 ++++++- src/catalogue/models/book.py | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/api/handlers.py b/src/api/handlers.py index 27477b3b2..92753357f 100644 --- a/src/api/handlers.py +++ b/src/api/handlers.py @@ -136,6 +136,11 @@ class BookDetails(object): return MEDIA_BASE + default.backend.get_thumbnail( book.cover, "139x193").url if book.cover else '' + @classmethod + def cover_source_image(cls, book): + url = book.cover_source() + return url.rstrip('/') + '/file/' + class BookDetailHandler(BaseHandler, BookDetails): """ Main handler for Book objects. @@ -262,7 +267,7 @@ class EBooksHandler(AnonymousBooksHandler): class FilterBooksHandler(AnonymousBooksHandler): - fields = book_tag_categories + ['href', 'title', 'url', 'cover', 'cover_thumb', 'slug'] + fields = book_tag_categories + ['href', 'title', 'url', 'cover', 'cover_thumb', 'slug', 'cover_source_image'] def read(self, request, title_part=None, author_part=None, is_lektura=None, is_audiobook=None, after=None, before=None, count=None): diff --git a/src/catalogue/models/book.py b/src/catalogue/models/book.py index 69d71aef2..3715e7b98 100644 --- a/src/catalogue/models/book.py +++ b/src/catalogue/models/book.py @@ -136,6 +136,9 @@ class Book(models.Model): others = '' return ', '.join(u'\xa0'.join(reversed(translator.split(', ', 1))) for translator in translators) + others + def cover_source(self): + return self.extra_info.get('cover_source', self.parent.cover_source() if self.parent else '') + def save(self, force_insert=False, force_update=False, **kwargs): from sortify import sortify -- 2.20.1