From: Jan Szejko Date: Mon, 27 Nov 2017 15:44:46 +0000 (+0100) Subject: quotes in API X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/51369735b0c2f71ee63c1403da3254d5efed2b93?ds=sidebyside;hp=-c quotes in API --- 51369735b0c2f71ee63c1403da3254d5efed2b93 diff --git a/src/api/handlers.py b/src/api/handlers.py index bc8843b16..6f7179bd5 100644 --- a/src/api/handlers.py +++ b/src/api/handlers.py @@ -280,7 +280,8 @@ class EBooksHandler(AnonymousBooksHandler): class FilterBooksHandler(AnonymousBooksHandler): - fields = book_tag_categories + ['href', 'title', 'url', 'cover', 'cover_thumb', 'slug', 'cover_source_image'] + fields = book_tag_categories + [ + 'href', 'title', 'url', 'cover', 'cover_thumb', 'slug', 'cover_source_image', 'fragment_data'] 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 3715e7b98..00921b899 100644 --- a/src/catalogue/models/book.py +++ b/src/catalogue/models/book.py @@ -615,6 +615,13 @@ class Book(models.Model): else: return None + def fragment_data(self): + fragment = self.choose_fragment() + if fragment: + return {'title': fragment.book.pretty_title(), 'html': fragment.get_short_text()} + else: + return None + def update_popularity(self): count = self.tags.filter(category='set').values('user').order_by('user').distinct().count() try: