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() ), )