'</resource><resource>'.join(self.construct().get_ssis('xml'))
Emitter.register('xml', SsiXmlEmitter, 'text/xml; charset=utf-8')
+
+
+# hack
+class EpubEmitter(Emitter):
+ def render(self, request):
+ return self.data
+
+Emitter.register('epub', EpubEmitter, 'application/epub+zip')
from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse
+from django.http.response import HttpResponse
from django.utils.functional import lazy
from django.db import models
from piston.handler import AnonymousBaseHandler, BaseHandler
from catalogue.forms import BookImportForm
from catalogue.models import Book, Tag, BookMedia, Fragment, Collection
from catalogue.models.tag import prefetch_relations
+from catalogue.utils import is_subscribed
from picture.models import Picture
from picture.forms import PictureImportForm
return rc.NOT_FOUND
+class EpubHandler(BookDetailHandler):
+ def read(self, request, slug):
+ if not is_subscribed(request.user):
+ return rc.FORBIDDEN
+ try:
+ book = Book.objects.get(slug=slug)
+ except Book.DoesNotExist:
+ return rc.NOT_FOUND
+ response = HttpResponse(book.get_media('epub'))
+ return response
+
+
class EBooksHandler(AnonymousBooksHandler):
fields = ('author', 'href', 'title', 'cover') + tuple(Book.ebook_formats) + ('slug',)
# book_list_resource = Resource(handler=handlers.BooksHandler)
book_resource = Resource(handler=handlers.BookDetailHandler)
filter_book_resource = Resource(handler=handlers.FilterBooksHandler)
+epub_resource = Resource(handler=handlers.EpubHandler)
collection_resource = Resource(handler=handlers.CollectionDetailHandler)
collection_list_resource = Resource(handler=handlers.CollectionsHandler)
url(r'^collections/$', collection_list_resource, name="api_collections"),
url(r'^collections/(?P<slug>[^/]+)/$', collection_resource, name="api_collection"),
+ # epub preview
+ url(r'^epub/(?P<slug>[a-z0-9-]+)/$', epub_resource, name='api_epub'),
+
# objects details
url(r'^books/(?P<book>[a-z0-9-]+)/$', book_resource, name="api_book"),
url(r'^(?P<category>[a-z0-9-]+)/(?P<slug>[a-z0-9-]+)/$',