""" Responsible for representing media in Books. """
model = BookMedia
- fields = ['name', 'type', 'url']
+ fields = ['name', 'type', 'url', 'artist', 'director']
@classmethod
def url(cls, media):
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."""
"""
allowed_methods = ['GET']
fields = ['title', 'parent', 'children'] + Book.formats + [
- 'media', 'url', 'cover'] + book_tag_categories
+ 'media', 'url', 'cover'] + [
+ category_plural[c] for c in book_tag_categories]
@piwik_track
def read(self, request, book):
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
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
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
</p>
<ul>
- <li><a href='/api/books/'>/api/books/</a> – {% trans "List of all books" %}
+ <li><a href='{% url "api_book_list" "" %}'>
+ {% url "api_book_list" "" %}</a> – {% trans "All books" %}
+ <li><a href='{% url "api_audiobook_list" "" %}'>
+ {% url "api_audiobook_list" "" %}</a> – {% trans "Audiobooks" %}
+ <li><a href='{% url "api_daisy_list" "" %}'>
+ {% url "api_daisy_list" "" %}</a> – {% trans "DAISY" %}
- <li><a href='/api/authors/'>/api/authors/</a> – {% trans "List of all authors" %}</li>
- <li><a href='/api/epochs/'>/api/epochs/</a> – {% trans "List of all epochs" %}</li>
- <li><a href='/api/genres/'>/api/genres/</a> – {% trans "List of all genres" %}</li>
- <li><a href='/api/kinds/'>/api/kinds/</a> – {% trans "List of all kinds" %}</li>
+ <li><a href='{% url "api_tag_list" "authors" %}'>
+ {% url "api_tag_list" "authors" %}</a> – {% trans "List of all authors" %}</li>
+ <li><a href='{% url "api_tag_list" "epochs" %}'>
+ {% url "api_tag_list" "epochs" %}</a> – {% trans "List of all epochs" %}</li>
+ <li><a href='{% url "api_tag_list" "genres" %}'>
+ {% url "api_tag_list" "genres" %}</a> – {% trans "List of all genres" %}</li>
+ <li><a href='{% url "api_tag_list" "kinds" %}'>
+ {% url "api_tag_list" "kinds" %}</a> – {% trans "List of all kinds" %}</li>
- <li><a href='/api/themes/'>/api/themes/</a> – {% trans "List of all themes" %}</li>
+ <li><a href='{% url "api_tag_list" "themes" %}'>
+ {% url "api_tag_list" "themes" %}</a> – {% trans "List of all themes" %}</li>
</ul>
<p>
fragment_resource, name="api_fragment"),
# books by tags
- url(r'^(?P<tags>(?:(?:[a-z0-9-]+/){2}){0,6})books/$', book_list_resource),
- url(r'^(?P<tags>(?:(?:[a-z0-9-]+/){2}){0,6})parent_books/$', book_list_resource, {"top_level": True}),
+ url(r'^(?P<tags>(?:(?:[a-z0-9-]+/){2}){0,6})books/$',
+ book_list_resource, name='api_book_list'),
+ url(r'^(?P<tags>(?:(?:[a-z0-9-]+/){2}){0,6})parent_books/$',
+ book_list_resource, {"top_level": True}, name='api_parent_book_list'),
+ url(r'^(?P<tags>(?:(?:[a-z0-9-]+/){2}){0,6})audiobooks/$',
+ book_list_resource, {"audiobooks": True}, name='api_audiobook_list'),
+ url(r'^(?P<tags>(?:(?:[a-z0-9-]+/){2}){0,6})daisy/$',
+ book_list_resource, {"daisy": True}, name='api_daisy_list'),
url(r'^pictures/$', picture_resource),
url(r'^(?P<tags>(?:(?:[a-z0-9-]+/){2}){1,6})fragments/$', fragment_list_resource),
# tags by category
- url(r'^(?P<category>[a-z0-9-]+)/$', tag_list_resource),
+ url(r'^(?P<category>[a-z0-9-]+)/$', tag_list_resource, name='api_tag_list'),
)