X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/86b624d26dbc858b0252200567b0db169df235c2..dbb6eb3883a5f5e371f4bf7c89e74326feca0fd1:/apps/api/handlers.py diff --git a/apps/api/handlers.py b/apps/api/handlers.py index b11a0a65f..260384d69 100644 --- a/apps/api/handlers.py +++ b/apps/api/handlers.py @@ -83,7 +83,7 @@ class BookMediaHandler(BaseHandler): """ Responsible for representing media in Books. """ model = BookMedia - fields = ['name', 'type', 'url'] + fields = ['name', 'type', 'url', 'artist', 'director'] @classmethod def url(cls, media): @@ -91,6 +91,15 @@ class BookMediaHandler(BaseHandler): return MEDIA_BASE + media.file.url + @classmethod + def artist(cls, media): + return media.get_extra_info_value().get('artist_name', '') + + @classmethod + def director(cls, media): + return media.get_extra_info_value().get('director_name', '') + + class BookDetails(object): """Custom fields used for representing Books.""" @@ -134,7 +143,8 @@ class BookDetailHandler(BaseHandler, BookDetails): """ allowed_methods = ['GET'] fields = ['title', 'parent', 'children'] + Book.formats + [ - 'media', 'url'] + book_tag_categories + 'media', 'url', 'cover'] + [ + category_plural[c] for c in book_tag_categories] @piwik_track def read(self, request, book): @@ -155,7 +165,8 @@ class AnonymousBooksHandler(AnonymousBaseHandler, BookDetails): fields = ['author', 'href', 'title', 'url', 'cover'] @piwik_track - def read(self, request, tags, top_level=False): + def read(self, request, tags, top_level=False, + audiobooks=False, daisy=False): """ Lists all books with given tags. :param tags: filtering tags; should be a path of categories @@ -175,17 +186,22 @@ class AnonymousBooksHandler(AnonymousBaseHandler, BookDetails): return books if books else rc.NOT_FOUND else: books = Book.tagged.with_all(tags) - elif top_level: - books = Book.objects.filter(parent=None) else: books = Book.objects.all() + + if top_level: + books = books.filter(parent=None) + if audiobooks: + books = books.filter(media__type='mp3') + if daisy: + books = books.filter(media__type='daisy') if books.exists(): return books else: return rc.NOT_FOUND - def create(self, request, tags, top_level=False): + def create(self, request, *args, **kwargs): return rc.FORBIDDEN @@ -195,7 +211,7 @@ class BooksHandler(BookDetailHandler): fields = ['author', 'href', 'title', 'url'] anonymous = AnonymousBooksHandler - def create(self, request, tags, top_level=False): + def create(self, request, *args, **kwargs): if not request.user.has_perm('catalogue.add_book'): return rc.FORBIDDEN