Automatically re-render PDF for files lost due to bug

This commit is contained in:
Raphael Michel
2018-05-28 11:41:41 +02:00
parent d65d48db48
commit 6ecddfc6c0
3 changed files with 26 additions and 9 deletions

View File

@@ -20,7 +20,8 @@ from pretix.base.models.orders import (
)
from pretix.base.payment import PaymentException
from pretix.base.services.invoices import (
generate_cancellation, generate_invoice, invoice_pdf, invoice_qualified,
generate_cancellation, generate_invoice, invoice_pdf, invoice_pdf_task,
invoice_qualified,
)
from pretix.base.services.orders import cancel_order
from pretix.base.services.tickets import (
@@ -673,6 +674,10 @@ class InvoiceDownload(EventViewMixin, OrderDetailMixin, View):
'now. Please try again in a few seconds.'))
return redirect(self.get_order_url())
resp = FileResponse(invoice.file.file, content_type='application/pdf')
try:
resp = FileResponse(invoice.file.file, content_type='application/pdf')
except FileNotFoundError:
invoice_pdf_task.apply(args=(invoice.pk,))
return self.get(request, *args, **kwargs)
resp['Content-Disposition'] = 'attachment; filename="{}.pdf"'.format(invoice.number)
return resp