1 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from .models import Book
6 from librarian import DocProvider
7 from django.http import HttpResponse
10 class RedakcjaDocProvider(DocProvider):
11 """Used for getting books' children."""
13 def __init__(self, publishable):
14 self.publishable = publishable
16 def by_slug(self, slug):
18 return BytesIO(Book.objects.get(catalogue_book_id=slug
19 ).materialize(publishable=self.publishable
23 def serve_file(file_path, name, mime_type):
24 def read_chunks(f, size=8192):
30 response = HttpResponse(content_type=mime_type)
31 response['Content-Disposition'] = 'attachment; filename=%s' % name
32 with open(file_path, 'rb') as f:
33 for chunk in read_chunks(f):