Add waffleswitch and hook it to email

This commit is contained in:
zandercymatics 2024-05-24 10:08:36 -06:00
parent ef4e758517
commit 6ad2546a40
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
6 changed files with 100 additions and 4 deletions

View file

@ -8,6 +8,7 @@ from django.template.loader import get_template
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from waffle import switch_is_active
logger = logging.getLogger(__name__)
@ -33,6 +34,9 @@ def send_templated_email(
context as Django's HTML templates. context gives additional information
that the template may use.
"""
if switch_is_active("disable_email_sending"):
raise EmailSendingError("Could not send email. Email sending is disabled due to switch 'disable_email_sending'.")
logger.info(f"An email was sent! Template name: {template_name} to {to_address}")
template = get_template(template_name)
email_body = template.render(context=context)