本文整理汇总了Python中webnotes.modules.scrub函数的典型用法代码示例。如果您正苦于以下问题:Python scrub函数的具体用法?Python scrub怎么用?Python scrub使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了scrub函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_page_path
def get_page_path(page_name, module):
"""get path of the page html file"""
import os
import conf
from webnotes.modules import scrub
return os.path.join(conf.modules_path, 'erpnext', scrub(module), \
'page', scrub(page_name), scrub(page_name) + '.html')
示例2: get_server_obj
def get_server_obj(doc, doclist = [], basedoctype = ''):
"""
Returns the instantiated `DocType` object. Will also manage caching & compiling
"""
# for test
import webnotes
from webnotes.modules import scrub
# get doctype details
module = webnotes.conn.get_value('DocType', doc.doctype, 'module')
# no module specified (must be really old), can't get code so quit
if not module:
return
module = scrub(module)
dt = scrub(doc.doctype)
try:
module = __import__('%s.doctype.%s.%s' % (module, dt, dt), fromlist=[''])
DocType = getattr(module, 'DocType')
except ImportError, e:
from webnotes.utils import cint
if not cint(webnotes.conn.get_value("DocType", doc.doctype, "custom")):
raise e
class DocType:
def __init__(self, d, dl):
self.doc, self.doclist = d, dl
示例3: run
def run(report_name, filters=None):
report = webnotes.doc("Report", report_name)
if filters and isinstance(filters, basestring):
filters = json.loads(filters)
if not webnotes.has_permission(report.ref_doctype, "report"):
webnotes.msgprint(_("Must have report permission to access this report."),
raise_exception=True)
if report.report_type=="Query Report":
if not report.query:
webnotes.msgprint(_("Must specify a Query to run"), raise_exception=True)
if not report.query.lower().startswith("select"):
webnotes.msgprint(_("Query must be a SELECT"), raise_exception=True)
result = [list(t) for t in webnotes.conn.sql(report.query, filters)]
columns = [c[0] for c in webnotes.conn.get_description()]
else:
method_name = scrub(webnotes.conn.get_value("DocType", report.ref_doctype, "module")) \
+ ".report." + scrub(report.name) + "." + scrub(report.name) + ".execute"
columns, result = webnotes.get_method(method_name)(filters or {})
result = get_filtered_data(report.ref_doctype, columns, result)
if cint(report.add_total_row) and result:
result = add_total_row(result, columns)
return {
"result": result,
"columns": columns
}
示例4: get_pages
def get_pages(m):
import importlib
pages = webnotes.conn.sql_list("""select name from tabPage where module=%s""", m)
prefix = "docs.dev.modules." + m + ".page."
docs = {
"_icon": "file-alt",
"_label": "Pages",
"_toc": [prefix + d for d in pages]
}
for p in pages:
page = webnotes.doc("Page", p)
mydocs = docs[p] = {
"_label": page.title or p,
"_type": "page",
}
update_readme(mydocs, m, "page", p)
mydocs["_modified"] = page.modified
# controller
page_name = scrub(p)
try:
page_controller = importlib.import_module(scrub(m) + ".page." + page_name + "." + page_name)
inspect_object_and_update_docs(mydocs, page_controller)
except ImportError, e:
pass
示例5: get_page_js
def get_page_js(page, module=None):
"""
Returns the js code of a page. Will replace $import (page) or $import(module.page)
with the code from the file
"""
import webnotes, os
from webnotes.modules import scrub, get_module_path
if type(page)==str:
page_name = page
else:
page_name, module = page.name, page.module
code = get_js_code(os.path.join(get_module_path(module), 'page', scrub(page_name), scrub(page_name)))
if not code and type(page)!=str:
code = page.script
# compile for import
if code and code.strip():
import re
p = re.compile('\$import\( (?P<name> [^)]*) \)', re.VERBOSE)
code = p.sub(sub_get_page_js, code)
return code
示例6: get_code
def get_code(module, dt, dn, extn, fieldname=None):
from webnotes.modules import scrub, get_module_path
import os, webnotes
# get module (if required)
if not module:
module = webnotes.conn.get_value(dt, dn, 'module')
# no module, quit
if not module:
return ''
# file names
if dt in ('Page','Doctype'):
dt, dn = scrub(dt), scrub(dn)
# get file name
fname = dn + '.' + extn
# code
code = ''
try:
file = open(os.path.join(get_module_path(scrub(module)), dt, dn, fname), 'r')
code = file.read()
file.close()
except IOError, e:
# no file, try from db
if fieldname:
code = webnotes.conn.get_value(dt, dn, fieldname)
示例7: get_from_files
def get_from_files(self, doc):
"""
Loads page info from files in module
"""
from webnotes.modules import get_module_path, scrub
import os
path = os.path.join(get_module_path(doc.module), 'page', scrub(doc.name))
# script
fpath = os.path.join(path, scrub(doc.name) + '.js')
if os.path.exists(fpath):
with open(fpath, 'r') as f:
doc.fields['__script'] = f.read()
# css
fpath = os.path.join(path, scrub(doc.name) + '.css')
if os.path.exists(fpath):
with open(fpath, 'r') as f:
doc.style = f.read()
# html
fpath = os.path.join(path, scrub(doc.name) + '.html')
if os.path.exists(fpath):
with open(fpath, 'r') as f:
doc.content = f.read()
示例8: get_from_files
def get_from_files(self):
"""
Loads page info from files in module
"""
from webnotes.modules import get_module_path, scrub
import os
path = os.path.join(get_module_path(self.doc.module), 'page', scrub(self.doc.name))
# script
fpath = os.path.join(path, scrub(self.doc.name) + '.js')
if os.path.exists(fpath):
with open(fpath, 'r') as f:
self.doc.script = f.read()
# css
fpath = os.path.join(path, scrub(self.doc.name) + '.css')
if os.path.exists(fpath):
with open(fpath, 'r') as f:
self.doc.style = f.read()
# html
fpath = os.path.join(path, scrub(self.doc.name) + '.html')
if os.path.exists(fpath):
with open(fpath, 'r') as f:
self.doc.content = f.read()
if webnotes.lang != 'en':
from webnotes.translate import update_lang_js
self.doc.script = update_lang_js(self.doc.script, path)
示例9: run
def run(report_name):
report = webnotes.doc("Report", report_name)
if not webnotes.has_permission(report.ref_doctype, "report"):
webnotes.msgprint(_("Must have report permission to access this report."),
raise_exception=True)
if report.report_type=="Query Report":
if not report.query:
webnotes.msgprint(_("Must specify a Query to run"), raise_exception=True)
if not report.query.lower().startswith("select"):
webnotes.msgprint(_("Query must be a SELECT"), raise_exception=True)
result = [list(t) for t in webnotes.conn.sql(report.query)]
columns = [c[0] for c in webnotes.conn.get_description()]
else:
from webnotes.modules import scrub
method_name = scrub(webnotes.conn.get_value("DocType", report.ref_doctype, "module")) \
+ ".report." + scrub(report.name) + "." + scrub(report.name) + ".execute"
columns, result = webnotes.get_method(method_name)()
return {
"result": result,
"columns": columns
}
示例10: get_code
def get_code(module, dt, dn, extn, is_static=None, fieldname=None):
from webnotes.modules import scrub, get_module_path
import os, webnotes
# get module (if required)
if not module:
module = webnotes.conn.sql("select module from `tab%s` where name=%s" % (dt,'%s'),dn)[0][0]
# no module, quit
if not module:
return ''
# file names
if scrub(dt) in ('page','doctype','search_criteria'):
dt, dn = scrub(dt), scrub(dn)
# get file name
fname = dn + '.' + extn
if is_static:
fname = dn + '_static.' + extn
# code
code = ''
try:
file = open(os.path.join(get_module_path(scrub(module)), dt, dn, fname), 'r')
code = file.read()
file.close()
except IOError, e:
# no file, try from db
if fieldname:
code = webnotes.conn.get_value(dt, dn, fieldname)
示例11: load_doctype_module
def load_doctype_module(doctype, module, prefix=""):
from webnotes.modules import scrub
_doctype, _module = scrub(doctype), scrub(module)
try:
module = __import__(get_module_name(doctype, module, prefix), fromlist=[''])
return module
except ImportError, e:
return None
示例12: load_doctype_module
def load_doctype_module(doctype, module, prefix=""):
import webnotes
from webnotes.modules import scrub
_doctype, _module = scrub(doctype), scrub(module)
try:
module = __import__(get_module_name(doctype, module, prefix), fromlist=[''])
return module
except ImportError, e:
# webnotes.errprint(webnotes.getTraceback())
return None
示例13: get_path
def get_path(module, doctype, docname, plugin=None, extn="py"):
from webnotes.modules import scrub
import os
if not module: module = webnotes.conn.get_value(doctype, docname, "module")
if not plugin: plugin = get_plugin_name(doctype, docname)
# site_abs_path/plugins/module/doctype/docname/docname.py
return os.path.join(get_plugin_path(scrub(plugin)), scrub(module),
scrub(doctype), scrub(docname), scrub(docname) + "." + extn)
示例14: get_script
def get_script(report_name):
report = webnotes.doc("Report", report_name)
script_path = os.path.join(get_module_path(webnotes.conn.get_value("DocType", report.ref_doctype, "module")),
"report", scrub(report.name), scrub(report.name) + ".js")
if os.path.exists(script_path):
with open(script_path, "r") as script:
return script.read()
else:
return "wn.query_reports['%s']={}" % report_name
示例15: rename_export
def rename_export(self, old_name):
# export the folders
self.export_doc()
import os, shutil
from webnotes.modules import get_module_path, scrub
path = os.path.join(get_module_path(self.doc.module), 'search_criteria', scrub(old_name))
# copy py/js files
self.copy_file(path, scrub(old_name), '.py')
self.copy_file(path, scrub(old_name), '.js')
self.copy_file(path, scrub(old_name), '.sql')