X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/92bcb49ab1a4bf73225b8dec1cf09fd6dff8a879..cc9a57b827d7303c37f3b2d271e7c2f661d30e45:/apps/catalogue/views.py?ds=inline diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index 7ead47115..eadaeca94 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -7,7 +7,7 @@ import itertools from django.conf import settings from django.template import RequestContext -from django.shortcuts import render_to_response, get_object_or_404 +from django.shortcuts import render_to_response, get_object_or_404, redirect from django.http import HttpResponse, HttpResponseRedirect, Http404, HttpResponsePermanentRedirect from django.core.urlresolvers import reverse from django.db.models import Q @@ -22,14 +22,14 @@ from ajaxable.utils import JSONResponse, AjaxableFormView from catalogue import models from catalogue import forms -from catalogue.utils import (split_tags, AttachmentHttpResponse, - async_build_pdf, MultiQuerySet) +from catalogue.utils import split_tags, MultiQuerySet, get_customized_pdf_path +from catalogue.tasks import build_custom_pdf from pdcounter import models as pdcounter_models from pdcounter import views as pdcounter_views from suggest.forms import PublishingSuggestForm from picture.models import Picture -from os import path +from waiter.models import WaitedFile staff_required = user_passes_test(lambda user: user.is_staff) @@ -538,12 +538,13 @@ def download_custom_pdf(request, slug, method='GET'): form = forms.CustomPDFForm(method == 'GET' and request.GET or request.POST) if form.is_valid(): cust = form.customizations - pdf_file = models.get_customized_pdf_path(book, cust) + pdf_file = 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.slug), file_path=pdf_file, mimetype="application/pdf") + url = WaitedFile.order(pdf_file, + lambda p: build_custom_pdf.delay(book.id, cust, p), + book.pretty_title() + ) + return redirect(url) else: raise Http404(_('Incorrect customization options for PDF')) else: @@ -554,6 +555,7 @@ class CustomPDFFormView(AjaxableFormView): form_class = forms.CustomPDFForm title = ugettext_lazy('Download custom PDF') submit = ugettext_lazy('Download') + honeypot = True def __call__(self, request): from copy import copy