fix: validate email template subject and minor refactor (#19102)
* fix: validate email template subject * chore: remove duplicate call to `json.loads` and minor refactor
This commit is contained in:
parent
dcae57475d
commit
d61748446b
1 changed files with 11 additions and 11 deletions
|
|
@ -9,33 +9,33 @@ from frappe.utils.jinja import validate_template
|
|||
|
||||
|
||||
class EmailTemplate(Document):
|
||||
@property
|
||||
def response_(self):
|
||||
return self.response_html if self.use_html else self.response
|
||||
|
||||
def validate(self):
|
||||
if self.use_html:
|
||||
validate_template(self.response_html)
|
||||
else:
|
||||
validate_template(self.response)
|
||||
validate_template(self.subject)
|
||||
validate_template(self.response_)
|
||||
|
||||
def get_formatted_subject(self, doc):
|
||||
return frappe.render_template(self.subject, doc)
|
||||
|
||||
def get_formatted_response(self, doc):
|
||||
if self.use_html:
|
||||
return frappe.render_template(self.response_html, doc)
|
||||
|
||||
return frappe.render_template(self.response, doc)
|
||||
return frappe.render_template(self.response_, doc)
|
||||
|
||||
def get_formatted_email(self, doc):
|
||||
if isinstance(doc, str):
|
||||
doc = json.loads(doc)
|
||||
|
||||
return {"subject": self.get_formatted_subject(doc), "message": self.get_formatted_response(doc)}
|
||||
return {
|
||||
"subject": self.get_formatted_subject(doc),
|
||||
"message": self.get_formatted_response(doc),
|
||||
}
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_email_template(template_name, doc):
|
||||
"""Returns the processed HTML of a email template with the given doc"""
|
||||
if isinstance(doc, str):
|
||||
doc = json.loads(doc)
|
||||
|
||||
email_template = frappe.get_doc("Email Template", template_name)
|
||||
return email_template.get_formatted_email(doc)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue