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 catalogue.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):
17 return BytesIO(Book.objects.get(dc_slug=slug
18 ).materialize(publishable=self.publishable
22 def serve_file(file_path, name, mime_type):
23 def read_chunks(f, size=8192):
29 response = HttpResponse(content_type=mime_type)
30 response['Content-Disposition'] = 'attachment; filename=%s' % name
31 with open(file_path, 'rb') as f:
32 for chunk in read_chunks(f):