Skip to content

Commit

Permalink
[minor] [enhancement] Email alert subject is also dynamic using Jinja
Browse files Browse the repository at this point in the history
  • Loading branch information
rmehta committed Oct 16, 2015
1 parent 62bdc98 commit 951cec9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions frappe/__init__.py
Expand Up @@ -738,6 +738,9 @@ def get_file_json(path):
def read_file(path, raise_not_found=False):
"""Open a file and return its content as Unicode."""
from frappe.utils import cstr
if isinstance(path, unicode):
path = path.encode("utf-8")

if os.path.exists(path):
with open(path, "r") as f:
return cstr(f.read())
Expand Down
5 changes: 3 additions & 2 deletions frappe/email/doctype/email_alert/email_alert.json
Expand Up @@ -56,6 +56,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"description": "To add dynamic subject, use jinja tags like\n\n<div><pre><code>{{ doc.name }} Delivered</code></pre></div>",
"fieldname": "subject",
"fieldtype": "Data",
"hidden": 0,
Expand Down Expand Up @@ -105,7 +106,7 @@
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Send Alert On",
"label": "Send Alert On",
"no_copy": 0,
"options": "\nNew\nSave\nSubmit\nCancel\nDays After\nDays Before\nValue Change",
"permlevel": 0,
Expand Down Expand Up @@ -411,7 +412,7 @@
"is_submittable": 0,
"issingle": 0,
"istable": 0,
"modified": "2015-10-02 07:38:47.925050",
"modified": "2015-10-16 01:35:51.254775",
"modified_by": "Administrator",
"module": "Email",
"name": "Email Alert",
Expand Down
6 changes: 5 additions & 1 deletion frappe/email/doctype/email_alert/email_alert.py
Expand Up @@ -94,7 +94,11 @@ def evaluate_alert(doc, alert, event):
if not recipients:
return

frappe.sendmail(recipients=recipients, subject=alert.subject,
subject = alert.subject
if "{" in subject:
subject = frappe.render_template(alert.subject, {"doc": doc, "alert": alert})

frappe.sendmail(recipients=recipients, subject=subject,
message= frappe.render_template(alert.message, {"doc": doc, "alert":alert}),
bulk=True, reference_doctype = doc.doctype, reference_name = doc.name,
attachments = [frappe.attach_print(doc.doctype, doc.name)] if alert.attach_print else None)

0 comments on commit 951cec9

Please sign in to comment.