This commit is contained in:
zandercymatics 2024-07-03 09:11:09 -06:00
parent a8fa24411e
commit 55a74f63dd
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 7 additions and 17 deletions

View file

@ -868,11 +868,9 @@ class DomainRequest(TimeStampedModel):
email_template_subject_name: str = "" email_template_subject_name: str = ""
# Check if the current email that we sent out is the same as our defaults. # Check if the current email that we sent out is the same as our defaults.
# If these hashes differ, then that means that we're sending custom content. # If these differ, then that means that we're sending custom content.
default_email_hash = self._get_action_needed_reason_email_hash() default_email = self.get_default_action_needed_reason_email(self.action_needed_reason)
current_email_hash = convert_string_to_sha256_hash(self.action_needed_reason_email) if self.action_needed_reason_email and self.action_needed_reason_email != default_email:
if self.action_needed_reason_email and default_email_hash != current_email_hash:
print(f"sending custom email for: {current_email_hash}")
email_template_name = "custom_email.txt" email_template_name = "custom_email.txt"
# Check for the "type" of action needed reason. # Check for the "type" of action needed reason.
@ -907,22 +905,20 @@ class DomainRequest(TimeStampedModel):
wrap_email=True, wrap_email=True,
) )
# TODO - rework this def get_default_action_needed_reason_email(self, action_needed_reason):
def _get_action_needed_reason_email_hash(self):
"""Returns the default email associated with the given action needed reason""" """Returns the default email associated with the given action needed reason"""
if self.action_needed_reason is None or self.action_needed_reason == self.ActionNeededReasons.OTHER: if action_needed_reason is None or action_needed_reason == self.ActionNeededReasons.OTHER:
return None return None
# Get the email body # Get the email body
template_path = f"emails/action_needed_reasons/{self.action_needed_reason}.txt" template_path = f"emails/action_needed_reasons/{action_needed_reason}.txt"
template = get_template(template_path) template = get_template(template_path)
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
# Return the content of the rendered views # Return the content of the rendered views
context = {"domain_request": self, "recipient": recipient} context = {"domain_request": self, "recipient": recipient}
body_text = template.render(context=context).strip().lstrip("\n") body_text = template.render(context=context).strip().lstrip("\n")
print(f"body: {body_text}") return body_text
return convert_string_to_sha256_hash(body_text)
@transition( @transition(
field="status", field="status",

View file

@ -322,9 +322,3 @@ def convert_queryset_to_dict(queryset, is_model=True, key="id"):
request_dict = {value[key]: value for value in queryset} request_dict = {value[key]: value for value in queryset}
return request_dict return request_dict
def convert_string_to_sha256_hash(string_to_convert: str):
if not string_to_convert:
return None
return hashlib.sha256(string_to_convert.encode('utf-8')).hexdigest()