+
+
+def download_custom_pdf(request, book_fileid):
+ kwargs = models.Book.split_fileid(book_fileid)
+ if kwargs is None:
+ raise Http404
+ book = get_object_or_404(models.Book, **kwargs)
+
+ if request.method == 'GET':
+ form = forms.CustomPDFForm(request.GET)
+ if form.is_valid():
+ cust = form.customizations
+ pdf_file = models.get_customized_pdf_path(book, cust)
+
+ if not path.exists(pdf_file):
+ result = async_build_pdf.delay(book.id, cust, pdf_file)
+ result.wait()
+ return AttachmentHttpResponse(file_name=("%s.pdf" % book_fileid), file_path=pdf_file, mimetype="application/pdf")
+ else:
+ raise Http404(_('Incorrect customization options for PDF'))
+ else:
+ raise Http404(_('Bad method'))