+
+
+def download_custom_pdf(request, slug):
+ book = models.Book.objects.get(slug=slug)
+ if request.method == 'GET':
+ form = forms.CustomPDFForm(request.GET)
+ if form.is_valid():
+ cust = form.customizations
+ h = hash(tuple(cust))
+ pdf_name = '%s-custom-%s' % (book.slug, h)
+ pdf_file = path.join(settings.MEDIA_ROOT, models.get_dynamic_path(None, pdf_name, ext='pdf'))
+
+ if not path.exists(pdf_file):
+ result = create_custom_pdf.delay(book.id, cust, pdf_name)
+ result.wait()
+ return AttachmentHttpResponse(file_name=("%s.pdf" % book.slug), file_path=pdf_file, mimetype="application/pdf")
+ else:
+ raise Http404(_('Incorrect customization options for PDF'))
+ else:
+ raise Http404(_('Bad method'))