+
+@never_cache
+def book_pdf(request, slug):
+ book = get_object_or_404(Book, slug=slug)
+ if not book.accessible(request):
+ return HttpResponseForbidden("Not authorized.")
+
+ # TODO: move to celery
+ doc = book.wldocument()
+ # TODO: error handling
+ pdf_file = doc.as_pdf()
+ from catalogue.ebook_utils import serve_file
+ return serve_file(pdf_file.get_filename(),
+ book.slug + '.pdf', 'application/pdf')
+
+
+@never_cache
+def book_epub(request, slug):
+ book = get_object_or_404(Book, slug=slug)
+ if not book.accessible(request):
+ return HttpResponseForbidden("Not authorized.")
+
+ # TODO: move to celery
+ doc = book.wldocument()
+ # TODO: error handling
+ epub = doc.as_epub().get_string()
+ response = HttpResponse(mimetype='application/epub+zip')
+ response['Content-Disposition'] = 'attachment; filename=%s' % book.slug + '.epub'
+ response.write(epub)
+ return response
+
+