X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/f67de73a6cabbef2d84dc79706cbeb4441800860..8132fc186eb0c5fd02c86828c3a4735754296d02:/apps/catalogue/views.py diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index 76001f9e..f6208056 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -235,7 +235,7 @@ def book_txt(request, slug): return HttpResponseForbidden("Not authorized.") doc = book.wldocument() - text = doc.as_text().get_string() + text = doc.as_text().get_bytes() response = http.HttpResponse(text, content_type='text/plain') response['Content-Disposition'] = 'attachment; filename=%s.txt' % slug return response @@ -250,7 +250,7 @@ def book_html(request, slug): doc = book.wldocument(parse_dublincore=False) html = doc.as_html(options={'gallery': "'%s'" % book.gallery_url()}) - html = html.get_string() if html is not None else '' + html = html.get_bytes() if html is not None else '' # response = http.HttpResponse(html, content_type='text/html') # return response # book_themes = {} @@ -264,7 +264,7 @@ def book_html(request, slug): @never_cache -def book_pdf(request, slug): +def book_pdf(request, slug, mobile=False): book = get_object_or_404(Book, slug=slug) if not book.accessible(request): return HttpResponseForbidden("Not authorized.") @@ -272,7 +272,8 @@ def book_pdf(request, slug): # TODO: move to celery doc = book.wldocument() # TODO: error handling - pdf_file = doc.as_pdf(cover=True, ilustr_path=book.gallery_path()) + customizations = ['26pt', 'nothemes', 'nomargins', 'notoc'] if mobile else None + pdf_file = doc.as_pdf(cover=True, ilustr_path=book.gallery_path(), customizations=customizations) from catalogue.ebook_utils import serve_file return serve_file(pdf_file.get_filename(), book.slug + '.pdf', 'application/pdf') @@ -287,7 +288,7 @@ def book_epub(request, slug): # TODO: move to celery doc = book.wldocument() # TODO: error handling - epub = doc.as_epub(ilustr_path=book.gallery_path()).get_string() + epub = doc.as_epub(ilustr_path=book.gallery_path()).get_bytes() response = HttpResponse(content_type='application/epub+zip') response['Content-Disposition'] = 'attachment; filename=%s' % book.slug + '.epub' response.write(epub) @@ -303,7 +304,7 @@ def book_mobi(request, slug): # TODO: move to celery doc = book.wldocument() # TODO: error handling - mobi = doc.as_mobi(ilustr_path=book.gallery_path()).get_string() + mobi = doc.as_mobi(ilustr_path=book.gallery_path()).get_bytes() response = HttpResponse(content_type='application/x-mobipocket-ebook') response['Content-Disposition'] = 'attachment; filename=%s' % book.slug + '.mobi' response.write(mobi)