2020-11-19 09:40:03 +01:00
|
|
|
from django.dispatch import receiver
|
|
|
|
from django.urls import resolve, reverse
|
|
|
|
|
2023-12-15 22:09:23 +01:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2020-11-19 09:40:03 +01:00
|
|
|
|
2023-12-15 22:09:23 +01:00
|
|
|
from pretix.base.models import Order
|
|
|
|
from pretix.base.signals import register_mail_placeholders, register_ticket_outputs
|
2020-11-19 09:40:03 +01:00
|
|
|
from pretix.base.email import SimpleFunctionalMailTextPlaceholder
|
|
|
|
from pretix.control.signals import nav_event_settings
|
2023-12-15 22:09:23 +01:00
|
|
|
from pretix.presale.signals import order_info_top
|
|
|
|
from django.template.loader import get_template
|
2020-11-19 09:40:03 +01:00
|
|
|
|
2023-12-15 22:09:23 +01:00
|
|
|
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"
|
|
|
|
)
|
2020-11-19 09:40:03 +01:00
|
|
|
def register_mail_secrets(sender, **kwargs):
|
2023-12-15 22:09:23 +01:00
|
|
|
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",
|
|
|
|
)
|
2020-11-19 09:40:03 +01:00
|
|
|
|
|
|
|
|
2023-12-15 22:09:23 +01:00
|
|
|
# @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")
|
2020-11-19 09:40:03 +01:00
|
|
|
def navbar_settings(sender, request, **kwargs):
|
|
|
|
url = resolve(request.path_info)
|
2023-12-15 22:09:23 +01:00
|
|
|
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)
|