Procházet zdrojové kódy

[minor] make email alert configurable, so we can use it list default print formats

version-14
Rushabh Mehta před 8 roky
rodič
revize
05c88fa3f0
8 změnil soubory, kde provedl 77 přidání a 20 odebrání
  1. +2
    -2
      frappe/email/doctype/email_alert/email_alert.json
  2. +28
    -14
      frappe/email/doctype/email_alert/email_alert.py
  3. +23
    -0
      frappe/email/doctype/email_alert/test_email_alert.js
  4. +1
    -1
      frappe/model/sync.py
  5. +3
    -2
      frappe/modules/import_file.py
  6. +9
    -0
      frappe/public/css/form.css
  7. +1
    -1
      frappe/public/js/frappe/form/control.js
  8. +10
    -0
      frappe/public/less/form.less

+ 2
- 2
frappe/email/doctype/email_alert/email_alert.json Zobrazit soubor

@@ -681,7 +681,7 @@
"collapsible": 0,
"columns": 0,
"default": "Add your message here",
"depends_on": "eval:!doc.is_standard",
"depends_on": "",
"fieldname": "message",
"fieldtype": "Code",
"hidden": 0,
@@ -808,7 +808,7 @@
"istable": 0,
"max_attachments": 0,
"menu_index": 0,
"modified": "2017-07-07 16:09:48.804218",
"modified": "2017-08-13 22:43:49.079330",
"modified_by": "Administrator",
"module": "Email",
"name": "Email Alert",


+ 28
- 14
frappe/email/doctype/email_alert/email_alert.py Zobrazit soubor

@@ -7,14 +7,18 @@ import json, os
from frappe import _
from frappe.model.document import Document
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.modules.utils import export_module_json, get_doc_module
from markdown2 import markdown
from six import string_types

class EmailAlert(Document):
def onload(self):
'''load message'''
if self.is_standard:
self.message = self.get_template()

def autoname(self):
if not self.name:
self.name = self.subject
@@ -31,6 +35,7 @@ class EmailAlert(Document):

self.validate_forbidden_types()
self.validate_condition()
self.validate_standard()

def on_update(self):
frappe.cache().hdel('email_alerts', self.document_type)
@@ -53,6 +58,10 @@ def get_context(context):
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):
temp_doc = frappe.new_doc(self.document_type)
if self.condition:
@@ -165,26 +174,31 @@ def get_context(context):
self.property_value, update_modified = False)
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):
'''load templates and run get_context'''
module = get_doc_module(self.module, self.doctype, self.name)
if module:
if hasattr(module, 'get_context'):
out = module.get_context(context)
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()
def get_documents_for_today(email_alert):


+ 23
- 0
frappe/email/doctype/email_alert/test_email_alert.js Zobrazit soubor

@@ -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()
]);

});

+ 1
- 1
frappe/model/sync.py Zobrazit soubor

@@ -42,7 +42,7 @@ def sync_for(app_name, force=0, sync_everything = False, verbose=False, reset_pe
if l:
for i, doc_path in enumerate(files):
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

frappe.db.commit()


+ 3
- 2
frappe/modules/import_file.py Zobrazit soubor

@@ -33,7 +33,7 @@ def get_file_path(module, dt, dn):
return path

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:
docs = read_doc_from_file(path)
except IOError:
@@ -86,7 +86,8 @@ def read_doc_from_file(path):

ignore_values = {
"Report": ["disabled"],
"Print Format": ["disabled"]
"Print Format": ["disabled"],
"Email Alert": ["enabled"]
}

ignore_doctypes = [""]


+ 9
- 0
frappe/public/css/form.css Zobrazit soubor

@@ -588,6 +588,15 @@ select.form-control {
.password-strength-message {
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 {
display: inline-block;
margin-top: -3px;


+ 1
- 1
frappe/public/js/frappe/form/control.js Zobrazit soubor

@@ -1802,7 +1802,7 @@ frappe.ui.form.ControlCode = frappe.ui.form.ControlText.extend({
this._super();
$(this.input_area).find("textarea")
.allowTabs()
.css({"height":"400px", "font-family": "Monaco, \"Courier New\", monospace"});
.addClass('control-code');
}
});



+ 10
- 0
frappe/public/less/form.less Zobrazit soubor

@@ -735,6 +735,16 @@ select.form-control {
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 {
display: inline-block;
margin-top: -3px;


Načítá se…
Zrušit
Uložit