Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use attendee email in the regular send mail flow #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions pretix_email_template_plugin/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,39 @@
from django.dispatch import receiver
from pretix.base.email import BaseMailTextPlaceholder
from pretix.base.signals import register_text_placeholders
from pretix.base.services.placeholders import SimpleFunctionalTextPlaceholder


class AttendeeEmailPlaceholder(BaseMailTextPlaceholder):
def get_best_email(position_or_address):
from pretix.base.models import InvoiceAddress, OrderPosition
if isinstance(position_or_address, InvoiceAddress):
return position_or_address.order.email
if isinstance(position_or_address, OrderPosition):
if position_or_address.attendee_email:
return position_or_address.attendee_email
else:
return position_or_address.order.email

class AttendeeOrOrderEmailPlaceholder(BaseMailTextPlaceholder):
def __init__(self):
self._identifier = "attendee_email"
self._identifier = "email"

@property
def required_context(self):
return ["order", "position"]
return ["position_or_address"]

@property
def identifier(self):
return self._identifier

def render(self, context):
position = context["position"]
return position.attendee_email
position_or_address = context["position_or_address"]
return get_best_email(position_or_address)

def render_sample(self, context):
return "[email protected]"


@receiver(register_text_placeholders, dispatch_uid="placeholder_custom")
@receiver(register_text_placeholders, dispatch_uid="placeholder_email")
def register_placeholder_renderers(sender, **kwargs):
return AttendeeEmailPlaceholder()
return AttendeeOrOrderEmailPlaceholder()
Loading