Allow ticket output providers to handle downloads externally (#1402)

* TicketOutput-Providers: Make preview optional; download/attachable optional; optional specific target; update doc

* Spelling fixes in doc

* Changes after code-review

* Changes after code-review

* Commit missing template file

* Allow for redirects instead of files

* Return HTTPResponse with Content-Type text/uri-list on API

* Update API-doc

* Add viewable to spellinglist, fixing doc-test
This commit is contained in:
Martin Gross
2019-10-21 14:05:09 +02:00
committed by Raphael Michel
parent 27538d220e
commit 03c760c2bb
14 changed files with 123 additions and 39 deletions

View File

@@ -8,7 +8,9 @@ from django.contrib import messages
from django.core.files import File
from django.db import transaction
from django.db.models import Exists, OuterRef, Q, Sum
from django.http import FileResponse, Http404, JsonResponse
from django.http import (
FileResponse, Http404, HttpResponseRedirect, JsonResponse,
)
from django.shortcuts import get_object_or_404, redirect
from django.utils.decorators import method_decorator
from django.utils.functional import cached_property
@@ -155,7 +157,8 @@ class OrderDetails(EventViewMixin, OrderDetailMixin, CartMixin, TicketPageMixin,
'text': provider.download_button_text or 'Download',
'icon': provider.download_button_icon or 'fa-download',
'identifier': provider.identifier,
'multi': provider.multi_download_enabled
'multi': provider.multi_download_enabled,
'javascript_required': provider.javascript_required
})
return buttons
@@ -249,7 +252,8 @@ class OrderPositionDetails(EventViewMixin, OrderPositionDetailMixin, CartMixin,
'text': provider.download_button_text or 'Download',
'icon': provider.download_button_icon or 'fa-download',
'identifier': provider.identifier,
'multi': provider.multi_download_enabled
'multi': provider.multi_download_enabled,
'javascript_required': provider.javascript_required
})
return buttons
@@ -793,12 +797,16 @@ class OrderDownloadMixin:
'message': str(self.get_success_message(value))
})
if isinstance(value, CachedTicket):
resp = FileResponse(value.file.file, content_type=value.type)
resp['Content-Disposition'] = 'attachment; filename="{}-{}-{}-{}{}"'.format(
self.request.event.slug.upper(), self.order.code, self.order_position.positionid,
self.output.identifier, value.extension
)
return resp
if value.type == 'text/uri-list':
resp = HttpResponseRedirect(value.file.file.read())
return resp
else:
resp = FileResponse(value.file.file, content_type=value.type)
resp['Content-Disposition'] = 'attachment; filename="{}-{}-{}-{}{}"'.format(
self.request.event.slug.upper(), self.order.code, self.order_position.positionid,
self.output.identifier, value.extension
)
return resp
elif isinstance(value, CachedCombinedTicket):
resp = FileResponse(value.file.file, content_type=value.type)
resp['Content-Disposition'] = 'attachment; filename="{}-{}-{}{}"'.format(