mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-11 13:40:38 +02:00
Further simplification
This commit is contained in:
parent
8ff6d52652
commit
41835d275f
2 changed files with 17 additions and 43 deletions
|
@ -1736,20 +1736,14 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
|
|
||||||
# == Handle action_needed_reason == #
|
# == Handle action_needed_reason == #
|
||||||
# Store the email that was sent out if one was sent and it isn't saved to a variable yet
|
# Store the email that was sent out if one was sent and it isn't saved to a variable yet
|
||||||
if not obj.action_needed_reason or obj.action_needed_reason == obj.ActionNeededReasons.OTHER:
|
default_email = self._get_action_needed_reason_default_email(obj, obj.action_needed_reason)
|
||||||
# Reset the action needed email to none if we don't send out an email.
|
if default_email:
|
||||||
obj.action_needed_reason_email = None
|
# Set the action_needed_reason_email to the default.
|
||||||
else:
|
# Since this check occurs after save, if the user enters a value then
|
||||||
# We send out an email -- store which one we send out.
|
# we won't update.
|
||||||
# Set the email to a default one if a custom email isn't provided.
|
|
||||||
default_email = self._get_action_needed_reason_default_email(obj, obj.action_needed_reason)
|
|
||||||
body_text = default_email.get("email_body_text")
|
|
||||||
|
|
||||||
# Set the action_needed_reason_email to the default
|
|
||||||
reason_changed = obj.action_needed_reason != original_obj.action_needed_reason
|
reason_changed = obj.action_needed_reason != original_obj.action_needed_reason
|
||||||
is_default_email = body_text == obj.action_needed_reason_email
|
if reason_changed and default_email == obj.action_needed_reason_email:
|
||||||
if body_text and is_default_email and reason_changed:
|
obj.action_needed_reason_email = default_email
|
||||||
obj.action_needed_reason_email = body_text
|
|
||||||
|
|
||||||
# == Handle status == #
|
# == Handle status == #
|
||||||
if obj.status == original_obj.status:
|
if obj.status == original_obj.status:
|
||||||
|
@ -1967,24 +1961,16 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
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:
|
||||||
if action_needed_reason != DomainRequest.ActionNeededReasons.OTHER:
|
# Map the action_needed_reason to its default email
|
||||||
enum_value = action_needed_reason.value
|
emails[action_needed_reason.value] = self._get_action_needed_reason_default_email(
|
||||||
custom_text = None
|
domain_request, action_needed_reason.value
|
||||||
if domain_request.action_needed_reason == enum_value and domain_request.action_needed_reason_email:
|
)
|
||||||
custom_text = domain_request.action_needed_reason_email
|
|
||||||
|
|
||||||
emails[enum_value] = self._get_action_needed_reason_default_email(
|
|
||||||
domain_request, enum_value, custom_text
|
|
||||||
)
|
|
||||||
return json.dumps(emails)
|
return json.dumps(emails)
|
||||||
|
|
||||||
def _get_action_needed_reason_default_email(self, domain_request, action_needed_reason, custom_text=None):
|
def _get_action_needed_reason_default_email(self, domain_request, action_needed_reason):
|
||||||
"""Returns the default email associated with the given action needed reason"""
|
"""Returns the default email associated with the given action needed reason"""
|
||||||
if not action_needed_reason:
|
if not action_needed_reason or action_needed_reason == DomainRequest.ActionNeededReasons.OTHER:
|
||||||
return {
|
return None
|
||||||
"subject_text": None,
|
|
||||||
"email_body_text": None,
|
|
||||||
}
|
|
||||||
|
|
||||||
if flag_is_active(None, "profile_feature"): # type: ignore
|
if flag_is_active(None, "profile_feature"): # type: ignore
|
||||||
recipient = domain_request.creator
|
recipient = domain_request.creator
|
||||||
|
@ -1994,27 +1980,15 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
# Return the context of the rendered views
|
# Return the context of the rendered views
|
||||||
context = {"domain_request": domain_request, "recipient": recipient}
|
context = {"domain_request": domain_request, "recipient": recipient}
|
||||||
|
|
||||||
# Get the email subject
|
|
||||||
template_subject_path = f"emails/action_needed_reasons/{action_needed_reason}_subject.txt"
|
|
||||||
subject_text = get_template(template_subject_path).render(context=context)
|
|
||||||
|
|
||||||
# Get the email body
|
# Get the email body
|
||||||
if not custom_text:
|
template_path = f"emails/action_needed_reasons/{action_needed_reason}.txt"
|
||||||
template_path = f"emails/action_needed_reasons/{action_needed_reason}.txt"
|
|
||||||
else:
|
|
||||||
template_path = "emails/action_needed_reasons/custom_email.txt"
|
|
||||||
context["custom_email_content"] = custom_text
|
|
||||||
|
|
||||||
email_body_text = get_template(template_path).render(context=context)
|
email_body_text = get_template(template_path).render(context=context)
|
||||||
|
|
||||||
email_body_text_cleaned = None
|
email_body_text_cleaned = None
|
||||||
if email_body_text:
|
if email_body_text:
|
||||||
email_body_text_cleaned = email_body_text.strip().lstrip("\n")
|
email_body_text_cleaned = email_body_text.strip().lstrip("\n")
|
||||||
|
|
||||||
return {
|
return email_body_text_cleaned
|
||||||
"subject_text": subject_text,
|
|
||||||
"email_body_text": email_body_text_cleaned,
|
|
||||||
}
|
|
||||||
|
|
||||||
def process_log_entry(self, log_entry):
|
def process_log_entry(self, log_entry):
|
||||||
"""Process a log entry and return filtered entry dictionary if applicable."""
|
"""Process a log entry and return filtered entry dictionary if applicable."""
|
||||||
|
|
|
@ -528,7 +528,7 @@ function initializeWidgetOnList(list, parentId) {
|
||||||
(function () {
|
(function () {
|
||||||
let actionNeededReasonDropdown = document.querySelector("#id_action_needed_reason");
|
let actionNeededReasonDropdown = document.querySelector("#id_action_needed_reason");
|
||||||
let actionNeededEmail = document.querySelector("#id_action_needed_reason_email");
|
let actionNeededEmail = document.querySelector("#id_action_needed_reason_email");
|
||||||
let actionNeededEmailData = document.getElementById('action-needed-emails-data').textContent);
|
let actionNeededEmailData = document.getElementById('action-needed-emails-data').textContent;
|
||||||
let noEmailMessage = document.getElementById("no-email-message");
|
let noEmailMessage = document.getElementById("no-email-message");
|
||||||
const emptyReasonText = "---------"
|
const emptyReasonText = "---------"
|
||||||
const noEmailText = "No email will be sent."
|
const noEmailText = "No email will be sent."
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue