pretix-digital-items/pretix_digital_items/textticketoutput.py
2020-11-19 09:40:03 +01:00

19 lines
945 B
Python

from pretix.base.ticketoutput import BaseTicketOutput
class TextTicketOutput(BaseTicketOutput):
identifier = 'tokens'
verbose_name = 'Download token as in simple textfile'
download_button_text = 'Download Token'
def generate(self, position):
token_export_format = "{name}: {secret}"
if position.event.settings.digitalitems_token_export_format:
token_export_format = position.event.settings.digitalitems_token_export_format
return 'token.txt', 'text/plain', token_export_format.format(secret = position.secret, name = str(position.item.name))
def generate_order(self, order):
token_export_format = "{name}: {secret}"
if order.event.settings.digitalitems_token_export_format:
token_export_format = order.event.settings.digitalitems_token_export_format
return 'tokens.txt', 'text/plain', '\n'.join(token_export_format.format(secret = position.secret, name = str(position.item.name)) for position in order.positions.all())