quotes in API
authorJan Szejko <janek37@gmail.com>
Mon, 27 Nov 2017 15:44:46 +0000 (16:44 +0100)
committerJan Szejko <janek37@gmail.com>
Mon, 27 Nov 2017 15:44:46 +0000 (16:44 +0100)
src/api/handlers.py
src/catalogue/models/book.py

index bc8843b..6f7179b 100644 (file)
@@ -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):
index 3715e7b..00921b8 100644 (file)
@@ -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: