浏览代码

custom scripts from file

version-14
Pratik Vyas 11 年前
父节点
当前提交
2ce962ed7e
共有 2 个文件被更改,包括 11 次插入20 次删除
  1. +10
    -19
      core/doctype/custom_script/custom_script.py
  2. +1
    -1
      webnotes/model/code.py

+ 10
- 19
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


+ 1
- 1
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:


正在加载...
取消
保存