- from tempfile import NamedTemporaryFile
- from os import unlink
- from librarian import pdf
- from catalogue.ebook_utils import RedakcjaDocProvider, serve_file
-
- xml = book.materialize()
- xml_file = NamedTemporaryFile()
- xml_file.write(xml.encode('utf-8'))
- xml_file.flush()
-
- try:
- pdf_file = NamedTemporaryFile(delete=False)
- pdf.transform(RedakcjaDocProvider(),
- file_path=xml_file.name,
- output_file=pdf_file,
- )
- return serve_file(pdf_file.name, book.slug + '.pdf', 'application/pdf')
- finally:
- unlink(pdf_file.name)
+ # TODO: move to celery
+ doc = book.wldocument()
+ # TODO: error handling
+ pdf_file = doc.as_pdf()
+ from catalogue.ebook_utils import serve_file
+ return serve_file(pdf_file.get_filename(),
+ book.slug + '.pdf', 'application/pdf')