This commit is contained in:
zandercymatics 2024-06-28 14:55:40 -06:00
parent 98be06e409
commit 7ddf1d87bc
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
4 changed files with 32 additions and 13 deletions

View file

@ -67,8 +67,8 @@ services:
# command: "python" # command: "python"
command: > command: >
bash -c " python manage.py migrate && bash -c " python manage.py migrate &&
python manage.py load &&
python manage.py createcachetable && python manage.py createcachetable &&
python manage.py load &&
python manage.py runserver 0.0.0.0:8080" python manage.py runserver 0.0.0.0:8080"
db: db:

View file

@ -1690,8 +1690,7 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
return super().save_model(request, obj, form, change) return super().save_model(request, obj, form, change)
# == Handle non-status changes == # # == Handle non-status changes == #
# Change this in #1901. Add a check on "not self.action_needed_reason_email" if obj.action_needed_reason and not self.action_needed_reason_email:
if obj.action_needed_reason:
self._handle_action_needed_reason_email(obj) self._handle_action_needed_reason_email(obj)
should_save = True should_save = True
@ -1911,13 +1910,16 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
# Call the superclass method with updated extra_context # Call the superclass method with updated extra_context
return super().change_view(request, object_id, form_url, extra_context) return super().change_view(request, object_id, form_url, extra_context)
# TODO - scrap this approach and just centralize everything
def get_all_action_needed_reason_emails_as_json(self, domain_request): def get_all_action_needed_reason_emails_as_json(self, domain_request):
"""Returns a json dictionary of every action needed reason and its associated email """Returns a json dictionary of every action needed reason and its associated email
for this particular domain request.""" for this particular domain request."""
emails = {} emails = {}
for action_needed_reason in domain_request.ActionNeededReasons: for action_needed_reason in domain_request.ActionNeededReasons:
enum_value = action_needed_reason.value enum_value = action_needed_reason.value
# Change this in #1901. Just add a check for the current value. if domain_request.action_needed_reason == enum_value and domain_request.action_needed_reason_email:
emails[enum_value] = domain_request.action_needed_reason_email
else:
emails[enum_value] = self._get_action_needed_reason_default_email_text(domain_request, enum_value) emails[enum_value] = self._get_action_needed_reason_default_email_text(domain_request, enum_value)
return json.dumps(emails) return json.dumps(emails)

View file

@ -672,7 +672,7 @@ class DomainRequest(TimeStampedModel):
logger.error(f"Can't query an approved domain while attempting {called_from}") logger.error(f"Can't query an approved domain while attempting {called_from}")
def _send_status_update_email( def _send_status_update_email(
self, new_status, email_template, email_template_subject, send_email=True, bcc_address="", wrap_email=False self, new_status, email_template, email_template_subject, bcc_address="", context=None, **kwargs
): ):
"""Send a status update email to the creator. """Send a status update email to the creator.
@ -683,13 +683,21 @@ class DomainRequest(TimeStampedModel):
If the waffle flag "profile_feature" is active, then this email will be sent to the If the waffle flag "profile_feature" is active, then this email will be sent to the
domain request creator rather than the submitter domain request creator rather than the submitter
kwargs:
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 wrap_email: bool -> Wraps emails using `wrap_text_and_preserve_paragraphs` if any given
paragraph exceeds our desired max length (for prettier display). paragraph exceeds our desired max length (for prettier display).
custom_email_content: str -> Renders an email with the content of this string as its body text.
""" """
# Email config options
wrap_email = kwargs.get("wrap_email", False)
send_email = kwargs.get("send_email", True)
custom_email_content = kwargs.get("custom_email_content", None)
recipient = self.creator if flag_is_active(None, "profile_feature") else self.submitter recipient = self.creator if flag_is_active(None, "profile_feature") else self.submitter
if recipient is None or recipient.email is None: if recipient is None or recipient.email is None:
logger.warning( logger.warning(
@ -705,15 +713,21 @@ class DomainRequest(TimeStampedModel):
return None return None
try: try:
send_templated_email( if not context:
email_template,
email_template_subject,
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
"recipient": recipient, "recipient": recipient,
}, }
if custom_email_content:
context["custom_email_content"] = custom_email_content
send_templated_email(
email_template,
email_template_subject,
recipient.email,
context=context,
bcc_address=bcc_address, bcc_address=bcc_address,
wrap_email=wrap_email, wrap_email=wrap_email,
) )
@ -844,12 +858,12 @@ class DomainRequest(TimeStampedModel):
if self.action_needed_reason and self.action_needed_reason != self.ActionNeededReasons.OTHER: if self.action_needed_reason and self.action_needed_reason != self.ActionNeededReasons.OTHER:
self._send_action_needed_reason_email(send_email) self._send_action_needed_reason_email(send_email)
def _send_action_needed_reason_email(self, send_email=True): def _send_action_needed_reason_email(self, send_email=True, custom_email_content=None):
"""Sends out an automatic email for each valid action needed reason provided""" """Sends out an automatic email for each valid action needed reason provided"""
# Store the filenames of the template and template subject # Store the filenames of the template and template subject
email_template_name: str = "" email_template_name: str = ""
email_template_subject_name: str = "" email_template_subject_name: str = "" if not custom_email_content else "custom_email"
# Check for the "type" of action needed reason. # Check for the "type" of action needed reason.
can_send_email = True can_send_email = True
@ -877,6 +891,7 @@ class DomainRequest(TimeStampedModel):
email_template_subject=f"emails/action_needed_reasons/{email_template_subject_name}", email_template_subject=f"emails/action_needed_reasons/{email_template_subject_name}",
send_email=send_email, send_email=send_email,
bcc_address=bcc_address, bcc_address=bcc_address,
custom_email_content=custom_email_content,
wrap_email=True, wrap_email=True,
) )

View file

@ -0,0 +1,2 @@
{% comment %} {% autoescape off %}{# In a text file, we don't want to have HTML entities escaped #} {% endcomment %}
{{ custom_email_content }}