pretix-digital-items/pretix_digital_items/textticketoutput.py

37 lines
1.2 KiB
Python
Raw Normal View History

2020-11-19 09:40:03 +01:00
from pretix.base.ticketoutput import BaseTicketOutput
2020-11-19 09:40:03 +01:00
class TextTicketOutput(BaseTicketOutput):
identifier = "tokens"
verbose_name = "Download token as in simple textfile"
download_button_text = "Download Token"
2020-11-19 09:40:03 +01:00
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)
),
)
2020-11-19 09:40:03 +01:00
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()
),
)