X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/92bcb49ab1a4bf73225b8dec1cf09fd6dff8a879..4bdb838df1fa9fa020acbb1cd53cc42341c45546:/apps/catalogue/views.py?ds=sidebyside diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index 7ead47115..0c05d17a8 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,7 +22,7 @@ from ajaxable.utils import JSONResponse, AjaxableFormView from catalogue import models from catalogue import forms -from catalogue.utils import (split_tags, AttachmentHttpResponse, +from catalogue.utils import (split_tags, async_build_pdf, MultiQuerySet) from pdcounter import models as pdcounter_models from pdcounter import views as pdcounter_views @@ -30,6 +30,7 @@ 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) @@ -540,10 +541,11 @@ def download_custom_pdf(request, slug, method='GET'): 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.slug), file_path=pdf_file, mimetype="application/pdf") + url = WaitedFile.order(pdf_file, + lambda p: async_build_pdf.delay(book.id, cust, p), + book.pretty_title() + ) + return redirect(url) else: raise Http404(_('Incorrect customization options for PDF')) else: