diff --git a/core/doctype/custom_script/custom_script.py b/core/doctype/custom_script/custom_script.py index fbe6edda76..9eea9e2673 100644 --- a/core/doctype/custom_script/custom_script.py +++ b/core/doctype/custom_script/custom_script.py @@ -42,4 +42,30 @@ def get_custom_server_script(doctype): webnotes.cache().set_value("_server_script:" + doctype, custom_script) return custom_script - + +def make_custom_server_scripts_path(): + from webnotes.utils import get_site_path + import os + + custom_scripts_path = get_site_path(webnotes.conf.get("custom_scripts_path")) + if not os.path.exists(custom_scripts_path): + os.mkdir(custom_scripts_path) + + return custom_scripts_path + +def make_custom_server_script_file(doctype, script=None): + from webnotes.modules import scrub + import os + + custom_scripts_path = make_custom_server_scripts_path() + + file_path = os.path.join(custom_scripts_path, scrub(doctype) + ".py") + + if os.path.exists(file_path): + raise Exception(file_path + " already exists") + + if not script: + script = "\tpass" + + with open(file_path, "w") as f: + f.write("class CustomDocType(DocType):\n" + script) \ No newline at end of file diff --git a/webnotes/__init__.py b/webnotes/__init__.py index 7082571b48..b84d35d3a5 100644 --- a/webnotes/__init__.py +++ b/webnotes/__init__.py @@ -588,6 +588,12 @@ def get_conf(site): import conf site_config = _dict({}) conf = site_config.update(conf.__dict__) + + if not conf.get("files_path"): + conf["files_path"] = os.path.join("public", "files") + if not conf.get("custom_scripts_path"): + conf["custom_scripts_path"] = "custom_scripts" + if conf.sites_dir and site: out = get_site_config(conf.sites_dir, site) if not out: @@ -598,8 +604,6 @@ def get_conf(site): return site_config else: - if not conf.get("files_path"): - conf["files_path"] = os.path.join("public", "files") return conf def get_site_config(sites_dir, site): diff --git a/webnotes/model/code.py b/webnotes/model/code.py index 80710f8e48..375482a612 100644 --- a/webnotes/model/code.py +++ b/webnotes/model/code.py @@ -15,19 +15,6 @@ methods in following modules are imported for backward compatibility * webnotes.model.doc.* * webnotes.model.bean.* """ -custom_class = ''' -import webnotes - -from webnotes.utils import cint, cstr, flt -from webnotes.model.doc import Document -from webnotes.model.code import get_obj -from webnotes import msgprint - -class CustomDocType(DocType): - def __init__(self, doc, doclist): - DocType.__init__(self, doc, doclist) -''' - def execute(code, doc=None, doclist=[]): # functions used in server script of DocTypes @@ -79,8 +66,6 @@ def get_server_obj(doc, doclist = [], basedoctype = ''): custom_script = get_custom_server_script(doc.doctype) if custom_script: - global custom_class - exec custom_script in locals() return CustomDocType(doc, doclist) diff --git a/webnotes/model/doctype.py b/webnotes/model/doctype.py index b151a2b5be..6b1e3c20cb 100644 --- a/webnotes/model/doctype.py +++ b/webnotes/model/doctype.py @@ -232,6 +232,7 @@ def clear_cache(doctype=None): def clear_single(dt): webnotes.cache().delete_value(cache_name(dt, False)) webnotes.cache().delete_value(cache_name(dt, True)) + webnotes.cache().delete_value("_server_script:" + dt) if doctype_cache and doctype in doctype_cache: del doctype_cache[dt]