Slight refactor

This commit is contained in:
zandercymatics 2024-06-24 11:07:26 -06:00
parent f42090fa30
commit 8659ad7f75
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7

View file

@ -677,24 +677,25 @@ class DomainRequest(TimeStampedModel):
send_email: bool -> Used to bypass the send_templated_email function, in the event send_email: bool -> Used to bypass the send_templated_email function, in the event
we just want to log that an email would have been sent, rather than actually sending one. we just want to log that an email would have been sent, rather than actually sending one.
wrap_email: bool -> Wraps emails using `wrap_text_and_preserve_paragraphs` if any given
paragraph exceeds our desired max length (for prettier display).
""" """
# Send the status update to the request creator recipient = self.creator if flag_is_active(None, "profile_feature") else self.submitter
to_address = self.creator.email if self.creator else None if recipient is None or recipient.email is None:
if to_address is None:
logger.warning(f"Cannot send {new_status} email, no creator email address.") logger.warning(f"Cannot send {new_status} email, no creator email address.")
return None return None
if not send_email: if not send_email:
logger.info(f"Email was not sent. Would send {new_status} email: {to_address}") logger.info(f"Email was not sent. Would send {new_status} email to: {recipient.email}")
return None return None
recipient = self.creator if flag_is_active(None, "profile_feature") else self.submitter
try: try:
send_templated_email( send_templated_email(
email_template, email_template,
email_template_subject, email_template_subject,
to_address, recipient.email,
context={ context={
"domain_request": self, "domain_request": self,
# This is the user that we refer to in the email # This is the user that we refer to in the email
@ -703,7 +704,7 @@ class DomainRequest(TimeStampedModel):
bcc_address=bcc_address, bcc_address=bcc_address,
wrap_email=wrap_email, wrap_email=wrap_email,
) )
logger.info(f"The {new_status} email sent to: {to_address}") logger.info(f"The {new_status} email sent to: {recipient.email}")
except EmailSendingError: except EmailSendingError:
logger.warning("Failed to send confirmation email", exc_info=True) logger.warning("Failed to send confirmation email", exc_info=True)