generated from bisco/codex-bootstrap
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import logging
|
|
|
|
from django.conf import settings
|
|
from django.core.mail import send_mail
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
CONFIRMATION_PATH = "/api/reservations/confirm/"
|
|
|
|
|
|
def build_confirmation_link(raw_confirmation_token):
|
|
return f"{settings.SITE_BASE_URL}{CONFIRMATION_PATH}?token={raw_confirmation_token}"
|
|
|
|
|
|
def send_confirmation_email(*, reservation, raw_confirmation_token):
|
|
confirmation_link = build_confirmation_link(raw_confirmation_token)
|
|
subject = f"Confirm your reservation for {reservation.performance.show.title}"
|
|
message = (
|
|
"Thank you for your reservation request.\n\n"
|
|
"Please confirm your reservation by opening this link:\n"
|
|
f"{confirmation_link}\n\n"
|
|
"If you did not request this reservation, you can ignore this email."
|
|
)
|
|
|
|
try:
|
|
send_mail(
|
|
subject=subject,
|
|
message=message,
|
|
from_email=None,
|
|
recipient_list=[reservation.email],
|
|
fail_silently=False,
|
|
)
|
|
except Exception:
|
|
logger.exception(
|
|
"Failed to send confirmation email for reservation %s.",
|
|
reservation.id,
|
|
)
|