diff --git a/core/doctype/custom_script/custom_script.py b/core/doctype/custom_script/custom_script.py index a080dd0171..fbe6edda76 100644 --- a/core/doctype/custom_script/custom_script.py +++ b/core/doctype/custom_script/custom_script.py @@ -15,23 +15,6 @@ class DocType: if self.doc.script_type=="Server" and webnotes.session.user!="Administrator": webnotes.throw("Only Administrator is allowed to edit Server Script") - # fix indentation - tabs = None - for line in self.doc.script.split("\n"): - if line.strip(): - for i, char in enumerate(line): - if char=="\t": - tabs = "\t" - break - if char!=" ": - if i==0: - webnotes.throw("Custom Script must be indented by one tab") - tabs = " " * i - break - if tabs: - break - - self.doc.script = self.doc.script.replace(tabs, " ") if not self.doc.script.startswith("\n"): self.doc.script = "\n" + self.doc.script @@ -44,10 +27,18 @@ class DocType: webnotes.cache().delete_value("_server_script:" + self.doc.dt) def get_custom_server_script(doctype): + from webnotes.modules import scrub + from webnotes import conf + from webnotes.utils import get_site_path + import os custom_script = webnotes.cache().get_value("_server_script:" + doctype) if not custom_script: - custom_script = webnotes.conn.get_value("Custom Script", {"dt": doctype, "script_type":"Server"}, - "script") or "" + script_path = get_site_path(conf.custom_scripts_path, scrub(doctype) + '.py') + if os.path.exists(script_path): + with open(script_path, 'r') as f: + custom_script = f.read() + else: + custom_script = None webnotes.cache().set_value("_server_script:" + doctype, custom_script) return custom_script diff --git a/webnotes/model/code.py b/webnotes/model/code.py index fa9ae0dc64..80710f8e48 100644 --- a/webnotes/model/code.py +++ b/webnotes/model/code.py @@ -81,7 +81,7 @@ def get_server_obj(doc, doclist = [], basedoctype = ''): if custom_script: global custom_class - exec custom_class + '\n' + custom_script.replace('\t',' ') in locals() + exec custom_script in locals() return CustomDocType(doc, doclist) else: