+@never_cache
+def book_mobi(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
+ mobi = doc.as_mobi(ilustr_path=book.gallery_path()).get_string()
+ response = HttpResponse(content_type='application/x-mobipocket-ebook')
+ response['Content-Disposition'] = 'attachment; filename=%s' % book.slug + '.mobi'
+ response.write(mobi)
+ return response
+
+