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

@@ -47,6 +47,9 @@ def generate_order(order: int, provider: str):
prov = response(order.event)
if prov.identifier == provider:
filename, ttype, data = prov.generate_order(order)
if ttype == 'text/uri-list':
continue
path, ext = os.path.splitext(filename)
for ct in CachedCombinedTicket.objects.filter(order=order, provider=provider):
ct.delete()
@@ -124,6 +127,9 @@ def get_tickets_for_order(order, base_position=None):
if not p.is_enabled:
continue
if p.download_handled_by_frontend:
continue
if p.multi_download_enabled and not base_position:
try:
if len(positions) == 0:

View File

@@ -46,12 +46,19 @@ class BaseTicketOutput:
filename, a file type and file content. The extension will be taken from the filename
which is otherwise ignored.
Alternatively, you can pass a tuple consisting of an arbitrary string, ``text/uri-list``
and a single URL. In this case, the user will be redirected to this link instead of
being asked to download a generated file.
.. note:: If the event uses the event series feature (internally called subevents)
and your generated ticket contains information like the event name or date,
you probably want to display the properties of the subevent. A common pattern
to do this would be a declaration ``ev = position.subevent or position.order.event``
and then access properties that are present on both classes like ``ev.name`` or
``ev.date_from``.
.. note:: Should you elect to use the URI redirection feature instead of offering downloads,
you should also set the ``multi_download_enabled``-property to ``False``.
"""
raise NotImplementedError()
@@ -161,3 +168,21 @@ class BaseTicketOutput:
The Font Awesome icon on the download button in the frontend.
"""
return 'fa-download'
@property
def preview_allowed(self) -> bool:
"""
By default, the ``generate()`` method is called for generating a preview in the pretix backend.
In case your plugin cannot generate previews for any reason, you can manually disable it here.
"""
return True
@property
def javascript_required(self) -> bool:
"""
If this property is set to true, the download-button for this ticket-type will not be displayed
when the user's browser has JavaScript disabled.
Defaults to ``False``
"""
return False