From 06f683606cf4ca9b3a745f25b66475273f5ed0bf Mon Sep 17 00:00:00 2001 From: Richard Liu Date: Wed, 9 Oct 2024 02:22:58 -0700 Subject: [PATCH] added attendee_email placeholder --- pretix_email_template_plugin/apps.py | 5 ++--- pretix_email_template_plugin/signals.py | 30 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/pretix_email_template_plugin/apps.py b/pretix_email_template_plugin/apps.py index ef1ea52..c4bc9aa 100644 --- a/pretix_email_template_plugin/apps.py +++ b/pretix_email_template_plugin/apps.py @@ -7,16 +7,15 @@ except ImportError: raise RuntimeError("Please use pretix 2.7 or above to run this plugin!") - class PluginApp(PluginConfig): default = True name = "pretix_email_template_plugin" - verbose_name = "Email Template" + verbose_name = "Email template helper" class PretixPluginMeta: name = gettext_lazy("Email Template") author = "Your name" - description = gettext_lazy("Short description") + description = gettext_lazy("More email template placeholders, such as {attendee_email}") visible = True version = __version__ category = "FEATURE" diff --git a/pretix_email_template_plugin/signals.py b/pretix_email_template_plugin/signals.py index a025794..022ffb9 100644 --- a/pretix_email_template_plugin/signals.py +++ b/pretix_email_template_plugin/signals.py @@ -1 +1,31 @@ # Register your receivers here +from django.dispatch import receiver + +from pretix.base.signals import register_text_placeholders +from pretix.base.email import BaseMailTextPlaceholder + +class AttendeeEmailPlaceholder(BaseMailTextPlaceholder): + def __init__(self): + self._identifier = "attendee_email" + + @property + def required_context(self): + return ["order", "position"] + + @property + def identifier(self): + return self._identifier + + def render(self, context): + position = context["position"] + # TODO: print statement for sanity check -- remove + print(f"attendee_email: {position.attendee_email}") + return position.attendee_email + + def render_sample(self, context): + return "richard@0xparc.org" + + +@receiver(register_text_placeholders, dispatch_uid="placeholder_custom") +def register_placeholder_renderers(sender, **kwargs): + return AttendeeEmailPlaceholder() \ No newline at end of file