Quellcode durchsuchen

Moved Custom Server Scripts to custom_scripts/doctype_name.py

version-14
Anand Doshi vor 11 Jahren
Ursprung
Commit
d274e04c1b
4 geänderte Dateien mit 34 neuen und 18 gelöschten Zeilen
  1. +27
    -1
      core/doctype/custom_script/custom_script.py
  2. +6
    -2
      webnotes/__init__.py
  3. +0
    -15
      webnotes/model/code.py
  4. +1
    -0
      webnotes/model/doctype.py

+ 27
- 1
core/doctype/custom_script/custom_script.py Datei anzeigen

@@ -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)

+ 6
- 2
webnotes/__init__.py Datei anzeigen

@@ -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):


+ 0
- 15
webnotes/model/code.py Datei anzeigen

@@ -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)


+ 1
- 0
webnotes/model/doctype.py Datei anzeigen

@@ -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]


Laden…
Abbrechen
Speichern