106 lines
3.3 KiB
Python
106 lines
3.3 KiB
Python
from django.dispatch import receiver
|
|
from django.urls import resolve, reverse
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from pretix.base.models import Order
|
|
from pretix.base.signals import register_mail_placeholders, register_ticket_outputs
|
|
from pretix.base.email import SimpleFunctionalMailTextPlaceholder
|
|
from pretix.control.signals import nav_event_settings
|
|
from pretix.presale.signals import order_info_top
|
|
from django.template.loader import get_template
|
|
|
|
from pretix.base.signals import register_mail_placeholders, register_ticket_outputs
|
|
from pretix.base.email import SimpleFunctionalMailTextPlaceholder
|
|
from pretix.control.signals import nav_event_settings
|
|
|
|
|
|
@receiver(
|
|
register_mail_placeholders, dispatch_uid="pretix_digital_items_mail_placeholder"
|
|
)
|
|
def register_mail_secrets(sender, **kwargs):
|
|
token_mail_format = "{name}: {secret}"
|
|
if sender.settings.digitalitems_token_mail_format:
|
|
token_mail_format = sender.settings.digitalitems_token_mail_format
|
|
return SimpleFunctionalMailTextPlaceholder(
|
|
"secrets",
|
|
["order"],
|
|
lambda order: "\n"
|
|
+ "\n\n".join(
|
|
token_mail_format.format(
|
|
secret=position.secret, name=str(position.item.name)
|
|
)
|
|
for position in order.positions.all()
|
|
if position.item.admission
|
|
),
|
|
"\nej7f73xs8vfmwvkk2p73yeve4fueq849\n\np8yct9752a897rpsmqzf7beby34a2w25\n\nwwqxtw6guy5s8c5tdarfhyez2ft2juap",
|
|
)
|
|
|
|
|
|
# @receiver(register_ticket_outputs, dispatch_uid="pretix_digital_items_ticket_output")
|
|
# def register_ticket_outputs(sender, **kwargs):
|
|
# from .textticketoutput import TextTicketOutput
|
|
#
|
|
# return TextTicketOutput
|
|
|
|
|
|
@receiver(nav_event_settings, dispatch_uid="pretix_digital_items_nav_settings")
|
|
def navbar_settings(sender, request, **kwargs):
|
|
url = resolve(request.path_info)
|
|
return [
|
|
{
|
|
"label": _("Digital Items"),
|
|
"url": reverse(
|
|
"plugins:pretix_digital_items:settings",
|
|
kwargs={
|
|
"event": request.event.slug,
|
|
"organizer": request.organizer.slug,
|
|
},
|
|
),
|
|
"active": url.namespace == "plugins:pretix_digital_items"
|
|
and url.url_name == "settings",
|
|
}
|
|
]
|
|
|
|
|
|
@receiver(order_info_top, dispatch_uid="pretix_digital_items_order_tokens")
|
|
def list_tokens(sender, request, order: Order, **kwargs):
|
|
if (order.status != Order.STATUS_PAID) or not order.positions.exists():
|
|
return
|
|
|
|
positions = [
|
|
p for p in order.positions.filter(item__admission=True, addon_to__isnull=True)
|
|
]
|
|
|
|
if not positions:
|
|
return
|
|
|
|
token_url_format = "http://localhost?token={secret}"
|
|
if sender.settings.digitalitems_token_url_format:
|
|
token_url_format = sender.settings.digitalitems_token_url_format
|
|
|
|
tokenUrls = list(
|
|
map(
|
|
lambda position: token_url_format.format(
|
|
secret=position.secret, name=str(position.item.name)
|
|
),
|
|
positions,
|
|
)
|
|
)
|
|
|
|
checkins = list(
|
|
map(
|
|
lambda position: position.checkins.count() != 0,
|
|
positions,
|
|
)
|
|
)
|
|
|
|
data = zip(positions, tokenUrls, checkins)
|
|
|
|
template = get_template("pretix_digital_items/tokens.html")
|
|
ctx = {
|
|
"data": data,
|
|
}
|
|
|
|
return template.render(ctx, request=request)
|