@@ -681,7 +681,7 @@ | |||||
"collapsible": 0, | "collapsible": 0, | ||||
"columns": 0, | "columns": 0, | ||||
"default": "Add your message here", | "default": "Add your message here", | ||||
"depends_on": "eval:!doc.is_standard", | |||||
"depends_on": "", | |||||
"fieldname": "message", | "fieldname": "message", | ||||
"fieldtype": "Code", | "fieldtype": "Code", | ||||
"hidden": 0, | "hidden": 0, | ||||
@@ -808,7 +808,7 @@ | |||||
"istable": 0, | "istable": 0, | ||||
"max_attachments": 0, | "max_attachments": 0, | ||||
"menu_index": 0, | "menu_index": 0, | ||||
"modified": "2017-07-07 16:09:48.804218", | |||||
"modified": "2017-08-13 22:43:49.079330", | |||||
"modified_by": "Administrator", | "modified_by": "Administrator", | ||||
"module": "Email", | "module": "Email", | ||||
"name": "Email Alert", | "name": "Email Alert", | ||||
@@ -7,14 +7,18 @@ import json, os | |||||
from frappe import _ | from frappe import _ | ||||
from frappe.model.document import Document | from frappe.model.document import Document | ||||
from frappe.core.doctype.role.role import get_emails_from_role | from frappe.core.doctype.role.role import get_emails_from_role | ||||
from frappe.utils import validate_email_add, nowdate | |||||
from frappe.utils.data import parse_val | |||||
from frappe.utils import validate_email_add, nowdate, parse_val, is_html | |||||
from frappe.utils.jinja import validate_template | from frappe.utils.jinja import validate_template | ||||
from frappe.modules.utils import export_module_json, get_doc_module | from frappe.modules.utils import export_module_json, get_doc_module | ||||
from markdown2 import markdown | from markdown2 import markdown | ||||
from six import string_types | from six import string_types | ||||
class EmailAlert(Document): | class EmailAlert(Document): | ||||
def onload(self): | |||||
'''load message''' | |||||
if self.is_standard: | |||||
self.message = self.get_template() | |||||
def autoname(self): | def autoname(self): | ||||
if not self.name: | if not self.name: | ||||
self.name = self.subject | self.name = self.subject | ||||
@@ -31,6 +35,7 @@ class EmailAlert(Document): | |||||
self.validate_forbidden_types() | self.validate_forbidden_types() | ||||
self.validate_condition() | self.validate_condition() | ||||
self.validate_standard() | |||||
def on_update(self): | def on_update(self): | ||||
frappe.cache().hdel('email_alerts', self.document_type) | frappe.cache().hdel('email_alerts', self.document_type) | ||||
@@ -53,6 +58,10 @@ def get_context(context): | |||||
pass | pass | ||||
""") | """) | ||||
def validate_standard(self): | |||||
if self.is_standard and not frappe.conf.developer_mode: | |||||
frappe.throw(_('Cannot edit Standard Email Alert. To edit, please disable this and duplicate it')) | |||||
def validate_condition(self): | def validate_condition(self): | ||||
temp_doc = frappe.new_doc(self.document_type) | temp_doc = frappe.new_doc(self.document_type) | ||||
if self.condition: | if self.condition: | ||||
@@ -165,26 +174,31 @@ def get_context(context): | |||||
self.property_value, update_modified = False) | self.property_value, update_modified = False) | ||||
doc.set(self.set_property_after_alert, self.property_value) | doc.set(self.set_property_after_alert, self.property_value) | ||||
def get_template(self): | |||||
module = get_doc_module(self.module, self.doctype, self.name) | |||||
def load_template(extn): | |||||
template = '' | |||||
template_path = os.path.join(os.path.dirname(module.__file__), | |||||
frappe.scrub(self.name) + extn) | |||||
if os.path.exists(template_path): | |||||
with open(template_path, 'r') as f: | |||||
template = f.read() | |||||
return template | |||||
return load_template('.html') or load_template('.md') | |||||
def load_standard_properties(self, context): | def load_standard_properties(self, context): | ||||
'''load templates and run get_context''' | |||||
module = get_doc_module(self.module, self.doctype, self.name) | module = get_doc_module(self.module, self.doctype, self.name) | ||||
if module: | if module: | ||||
if hasattr(module, 'get_context'): | if hasattr(module, 'get_context'): | ||||
out = module.get_context(context) | out = module.get_context(context) | ||||
if out: context.update(out) | if out: context.update(out) | ||||
def load_template(extn): | |||||
template_path = os.path.join(os.path.dirname(module.__file__), | |||||
frappe.scrub(self.name) + extn) | |||||
if os.path.exists(template_path): | |||||
with open(template_path, 'r') as f: | |||||
self.message = f.read() | |||||
return True | |||||
# get template | |||||
if not load_template('.html'): | |||||
if load_template('.md'): | |||||
self.message = markdown(self.message) | |||||
self.message = self.get_template() | |||||
if not is_html(self.message): | |||||
self.message = markdown(self.message) | |||||
@frappe.whitelist() | @frappe.whitelist() | ||||
def get_documents_for_today(email_alert): | def get_documents_for_today(email_alert): | ||||
@@ -0,0 +1,23 @@ | |||||
/* eslint-disable */ | |||||
// rename this file from _test_[name] to test_[name] to activate | |||||
// and remove above this line | |||||
QUnit.test("test: Email Alert", function (assert) { | |||||
let done = assert.async(); | |||||
// number of asserts | |||||
assert.expect(1); | |||||
frappe.run_serially([ | |||||
// insert a new Email Alert | |||||
() => frappe.tests.make('Email Alert', [ | |||||
// values to be set | |||||
{key: 'value'} | |||||
]), | |||||
() => { | |||||
assert.equal(cur_frm.doc.key, 'value'); | |||||
}, | |||||
() => done() | |||||
]); | |||||
}); |
@@ -42,7 +42,7 @@ def sync_for(app_name, force=0, sync_everything = False, verbose=False, reset_pe | |||||
if l: | if l: | ||||
for i, doc_path in enumerate(files): | for i, doc_path in enumerate(files): | ||||
import_file_by_path(doc_path, force=force, ignore_version=True, | import_file_by_path(doc_path, force=force, ignore_version=True, | ||||
reset_permissions=reset_permissions) | |||||
reset_permissions=reset_permissions, for_sync=True) | |||||
#print module_name + ' | ' + doctype + ' | ' + name | #print module_name + ' | ' + doctype + ' | ' + name | ||||
frappe.db.commit() | frappe.db.commit() | ||||
@@ -33,7 +33,7 @@ def get_file_path(module, dt, dn): | |||||
return path | return path | ||||
def import_file_by_path(path, force=False, data_import=False, pre_process=None, ignore_version=None, | def import_file_by_path(path, force=False, data_import=False, pre_process=None, ignore_version=None, | ||||
reset_permissions=False): | |||||
reset_permissions=False, for_sync=False): | |||||
try: | try: | ||||
docs = read_doc_from_file(path) | docs = read_doc_from_file(path) | ||||
except IOError: | except IOError: | ||||
@@ -86,7 +86,8 @@ def read_doc_from_file(path): | |||||
ignore_values = { | ignore_values = { | ||||
"Report": ["disabled"], | "Report": ["disabled"], | ||||
"Print Format": ["disabled"] | |||||
"Print Format": ["disabled"], | |||||
"Email Alert": ["enabled"] | |||||
} | } | ||||
ignore_doctypes = [""] | ignore_doctypes = [""] | ||||
@@ -588,6 +588,15 @@ select.form-control { | |||||
.password-strength-message { | .password-strength-message { | ||||
margin-top: -10px; | margin-top: -10px; | ||||
} | } | ||||
.control-code { | |||||
height: 400px; | |||||
font-family: Monaco, "Courier New", monospace; | |||||
background-color: black; | |||||
color: #fffce7; | |||||
font-size: 12px; | |||||
line-height: 1.7em; | |||||
border: none; | |||||
} | |||||
.delivery-status-indicator { | .delivery-status-indicator { | ||||
display: inline-block; | display: inline-block; | ||||
margin-top: -3px; | margin-top: -3px; | ||||
@@ -1802,7 +1802,7 @@ frappe.ui.form.ControlCode = frappe.ui.form.ControlText.extend({ | |||||
this._super(); | this._super(); | ||||
$(this.input_area).find("textarea") | $(this.input_area).find("textarea") | ||||
.allowTabs() | .allowTabs() | ||||
.css({"height":"400px", "font-family": "Monaco, \"Courier New\", monospace"}); | |||||
.addClass('control-code'); | |||||
} | } | ||||
}); | }); | ||||
@@ -735,6 +735,16 @@ select.form-control { | |||||
margin-top: -10px; | margin-top: -10px; | ||||
} | } | ||||
.control-code { | |||||
height: 400px; | |||||
font-family: Monaco, "Courier New", monospace; | |||||
background-color: black; | |||||
color: @light-yellow; | |||||
font-size: 12px; | |||||
line-height: 1.7em; | |||||
border: none; | |||||
} | |||||
.delivery-status-indicator { | .delivery-status-indicator { | ||||
display: inline-block; | display: inline-block; | ||||
margin-top: -3px; | margin-top: -3px; | ||||