X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/5913c54d19b8f6775633176032161d49f9b2f1aa..30423c0a921a37cc2213e83309d5abe04399ba15:/src/catalogue/ebook_utils.py diff --git a/src/catalogue/ebook_utils.py b/src/catalogue/ebook_utils.py index dae2e769..c3e8b680 100644 --- a/src/catalogue/ebook_utils.py +++ b/src/catalogue/ebook_utils.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from StringIO import StringIO +from io import BytesIO from catalogue.models import Book from librarian import DocProvider from django.http import HttpResponse @@ -12,7 +12,7 @@ class RedakcjaDocProvider(DocProvider): self.publishable = publishable def by_slug(self, slug): - return StringIO(Book.objects.get(dc_slug=slug + return BytesIO(Book.objects.get(dc_slug=slug ).materialize(publishable=self.publishable ).encode('utf-8')) @@ -26,7 +26,7 @@ def serve_file(file_path, name, mime_type): response = HttpResponse(content_type=mime_type) response['Content-Disposition'] = 'attachment; filename=%s' % name - with open(file_path) as f: + with open(file_path, 'rb') as f: for chunk in read_chunks(f): response.write(chunk) return response