Beispiel #1
0
def get_test_doclist(doctype, name=None):
    """get test doclist, collection of doclists"""
    import os, webnotes
    from webnotes import conf
    from webnotes.modules.utils import peval_doclist
    from webnotes.modules import scrub

    doctype = scrub(doctype)
    doctype_path = os.path.join(
        os.path.dirname(os.path.abspath(conf.__file__)), conf.test_data_path,
        doctype)

    if name:
        with open(os.path.join(doctype_path,
                               scrub(name) + '.txt'), 'r') as txtfile:
            doclist = peval_doclist(txtfile.read())

        return doclist

    else:
        all_doclists = []
        for fname in filter(lambda n: n.endswith('.txt'),
                            os.listdir(doctype_path)):
            with open(os.path.join(doctype_path, scrub(fname)),
                      'r') as txtfile:
                all_doclists.append(peval_doclist(txtfile.read()))

        return all_doclists
Beispiel #2
0
	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)
Beispiel #3
0
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')
Beispiel #4
0
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)
Beispiel #5
0
    def on_update(self):
        """
			Writes the .txt for this page and if write_content is checked,
			it will write out a .html file
		"""
        from webnotes import conf
        from core.doctype.doctype.doctype import make_module_and_roles
        make_module_and_roles(self.doclist, "Page Role")

        if not webnotes.flags.in_import and getattr(
                conf, 'developer_mode', 0) and self.doc.standard == 'Yes':
            from webnotes.modules.export_file import export_to_files
            from webnotes.modules import get_module_path, scrub
            import os
            export_to_files(record_list=[['Page', self.doc.name]])

            # write files
            path = os.path.join(get_module_path(self.doc.module), 'page',
                                scrub(self.doc.name), scrub(self.doc.name))

            # js
            if not os.path.exists(path + '.js'):
                with open(path + '.js', 'w') as f:
                    f.write("""wn.pages['%s'].onload = function(wrapper) { 
	wn.ui.make_app_page({
		parent: wrapper,
		title: '%s',
		single_column: true
	});					
}""" % (self.doc.name, self.doc.title))
Beispiel #6
0
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
Beispiel #7
0
	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)
Beispiel #8
0
	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()
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
	}
Beispiel #10
0
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
Beispiel #11
0
    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()
Beispiel #12
0
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
Beispiel #13
0
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
Beispiel #14
0
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)
Beispiel #15
0
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
	}
Beispiel #16
0
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)
Beispiel #17
0
	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()
Beispiel #18
0
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)
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
Beispiel #20
0
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
Beispiel #21
0
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
Beispiel #22
0
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
Beispiel #23
0
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
Beispiel #24
0
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)
Beispiel #25
0
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
Beispiel #26
0
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()
	elif report.javascript:
		return report.javascript
	else:
		return "wn.query_reports['%s']={}" % report_name
Beispiel #27
0
	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')
Beispiel #28
0
def diff_ref_db():
	"""get diff using database as reference"""
	from webnotes.modules import scrub
	for dt in dt_map:
		# get all main docs
		for doc in webnotes.conn.sql("""select * from `tab%s`""" % dt, as_dict=1):
			# get file for this doc
			doc['doctype'] = dt
			path = os.path.join(webnotes.defs.modules_path, scrub(doc['module']), \
				scrub(dt), scrub(doc['name']), scrub(doc['name']) + '.txt')
				
			if os.path.exists(path):
				with open(path, 'r') as txtfile:
					target = peval_doclist(txtfile.read())					
			else:
				target = [None,]
			
			doc_diff(doc, target[0])
			
			# do diff for child records
			if target[0] and dt_map[dt].keys():
				for child_dt in dt_map[dt]:					

					# for each child type, we need to create
					# a key (e.g. fieldname, label) based mapping of child records in 
					# txt files
					child_key_map = {}
					keys = dt_map[dt][child_dt]
					for target_d in target:
						if target_d['doctype'] == child_dt:
							for key in keys:
								if target_d.get(key):
									child_key_map[target_d.get(key)] = target_d
									break

					for d in webnotes.conn.sql("""select * from `tab%s` where 
						parent=%s and docstatus<2""" % (child_dt, '%s'), doc['name'], as_dict=1):

						source_key = None
						d['doctype'] = child_dt
						for key in keys:
							if d.get(key):
								source_key = d.get(key)
								break
						
						# only if a key is found
						if source_key:
							doc_diff(d, child_key_map.get(source_key), source_key)
				

	print_stats()
Beispiel #29
0
    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')
def upload():
    from webnotes.utils.datautils import read_csv_content_from_uploaded_file
    from webnotes.modules import scrub

    rows = read_csv_content_from_uploaded_file()
    if not rows:
        msg = [_("Please select a csv file")]
        return {"messages": msg, "error": msg}
    columns = [scrub(f) for f in rows[4]]
    columns[0] = "name"
    columns[3] = "att_date"
    ret = []
    error = False

    from webnotes.utils.datautils import check_record, import_doc

    doctype_dl = webnotes.get_doctype("Attendance")

    for i, row in enumerate(rows[5:]):
        if not row:
            continue
        row_idx = i + 5
        d = webnotes._dict(zip(columns, row))
        d["doctype"] = "Attendance"
        if d.name:
            d["docstatus"] = webnotes.conn.get_value("Attendance", d.name, "docstatus")

        try:
            check_record(d, doctype_dl=doctype_dl)
            ret.append(import_doc(d, "Attendance", 1, row_idx, submit=True))
        except Exception, e:
            error = True
            ret.append("Error for row (#%d) %s : %s" % (row_idx, len(row) > 1 and row[1] or "", cstr(e)))
            webnotes.errprint(webnotes.getTraceback())
Beispiel #31
0
def write_document_file(doclist, record_module=None):
    """
		Write a doclist to file, can optionally specify module name
	"""
    import os
    from webnotes.model.utils import pprint_doclist

    module = get_module_name(doclist, record_module)

    # create the folder
    code_type = doclist[0]['doctype'] in ['DocType', 'Page', 'Search Criteria']

    # create folder
    folder = create_folder(module, doclist[0]['doctype'], doclist[0]['name'])

    # separate code files
    clear_code_fields(doclist, folder, code_type)

    # write the data file
    fname = (code_type and scrub(doclist[0]['name'])) or doclist[0]['name']

    txtfile = open(os.path.join(folder, fname + '.txt'), 'w+')
    txtfile.write(pprint_doclist(doclist))
    #dict_list = [pprint_dict(d) for d in doclist]
    #txtfile.write('[\n' + ',\n'.join(dict_list) + '\n]')
    txtfile.close()
Beispiel #32
0
def upload():
    from webnotes.utils.datautils import read_csv_content_from_uploaded_file
    from webnotes.modules import scrub

    rows = read_csv_content_from_uploaded_file()
    if not rows:
        msg = [_("Please select a csv file")]
        return {"messages": msg, "error": msg}
    columns = [scrub(f) for f in rows[4]]
    columns[0] = "name"
    columns[3] = "att_date"
    ret = []
    error = False

    from webnotes.utils.datautils import check_record, import_doc
    doctype_dl = webnotes.get_doctype("Attendance")

    for i, row in enumerate(rows[5:]):
        if not row: continue
        row_idx = i + 5
        d = webnotes._dict(zip(columns, row))
        d["doctype"] = "Attendance"
        if d.name:
            d["docstatus"] = webnotes.conn.get_value("Attendance", d.name,
                                                     "docstatus")

        try:
            check_record(d, doctype_dl=doctype_dl)
            ret.append(import_doc(d, "Attendance", 1, row_idx, submit=True))
        except Exception, e:
            error = True
            ret.append('Error for row (#%d) %s : %s' %
                       (row_idx, len(row) > 1 and row[1] or "", cstr(e)))
            webnotes.errprint(webnotes.getTraceback())
Beispiel #33
0
def write_document_file(doclist, record_module=None):
	import os
	from webnotes.utils import pprint_dict

	global updated_modules

	# module name
	if doclist[0]['doctype'] == 'Module Def':
		module = doclist[0]['name']
	elif doclist[0]['doctype']=='Control Panel':
		module = 'System'
	elif record_module:
		module = record_module
	else:
		module = doclist[0]['module']

	updated_modules.append(module)

	# create the folder
	code_type = doclist[0]['doctype'] in ['DocType','Page','Search Criteria']
	
	# create folder
	folder = create_folder(module, doclist[0]['doctype'], doclist[0]['name'])
	
	# separate code files
	clear_code_fields(doclist, folder, code_type)
		
	# write the data file	
	fname = (code_type and scrub(doclist[0]['name'])) or doclist[0]['name']
	dict_list = [pprint_dict(d) for d in doclist]	
	
	txtfile = open(os.path.join(folder, fname +'.txt'),'w+')	
	txtfile.write('[\n' + ',\n'.join(dict_list) + '\n]')
	txtfile.close()
Beispiel #34
0
	def on_update(self):
		"""
			Writes the .txt for this page and if write_content is checked,
			it will write out a .html file
		"""
		import conf
		from webnotes.modules.import_file import in_import
		if not in_import and getattr(conf,'developer_mode', 0) and self.doc.standard=='Yes':
			from webnotes.modules.export_file import export_to_files
			from webnotes.modules import get_module_path, scrub
			import os
			export_to_files(record_list=[['Page', self.doc.name]])
	
			# write files
			path = os.path.join(get_module_path(self.doc.module), 'page', scrub(self.doc.name), scrub(self.doc.name))
								
			# js
			if not os.path.exists(path + '.js'):
				with open(path + '.js', 'w') as f:
					f.write("""wn.pages['%s'].onload = function(wrapper) { 
	wn.ui.make_app_page({
		parent: wrapper,
		title: '%s',
		single_column: true
	});					
}""" % (self.doc.name, self.doc.title))
Beispiel #35
0
	def copy_file(self, path, old_name, extn):
		import os
		from webnotes.modules import get_module_path, scrub

		if os.path.exists(os.path.join(path, old_name + extn)):
			os.system('cp %s %s' % (os.path.join(path, old_name + extn), \
			os.path.join(get_module_path(self.doc.module), 'search_criteria', scrub(self.doc.name), scrub(self.doc.name) + extn)))
Beispiel #36
0
    def copy_file(self, path, old_name, extn):
        import os
        from webnotes.modules import get_module_path, scrub

        if os.path.exists(os.path.join(path, old_name + extn)):
            os.system('cp %s %s' % (os.path.join(path, old_name + extn), \
            os.path.join(get_module_path(self.doc.module), 'search_criteria', scrub(self.doc.name), scrub(self.doc.name) + extn)))
Beispiel #37
0
def write_document_file(doclist, record_module=None):
	"""
		Write a doclist to file, can optionally specify module name
	"""
	import os
	from webnotes.model.utils import pprint_doclist

	module = get_module_name(doclist, record_module)

	# create the folder
	code_type = doclist[0]['doctype'] in ['DocType','Page','Search Criteria']
	
	# create folder
	folder = create_folder(module, doclist[0]['doctype'], doclist[0]['name'])
	
	# separate code files
	clear_code_fields(doclist, folder, code_type)
		
	# write the data file	
	fname = (code_type and scrub(doclist[0]['name'])) or doclist[0]['name']
	txtfile = open(os.path.join(folder, fname +'.txt'),'w+')
	txtfile.write(pprint_doclist(doclist))
	#dict_list = [pprint_dict(d) for d in doclist]	
	#txtfile.write('[\n' + ',\n'.join(dict_list) + '\n]')
	txtfile.close()
Beispiel #38
0
def get_doctype_js(dt):
	import webnotes, os
	from webnotes.modules import scrub, get_module_path
	
	dt_details = webnotes.conn.sql('select module, client_script from tabDocType where name = %s', dt)
	module = scrub(dt_details[0][0])

	code = get_js_code(os.path.join(get_module_path(scrub(module)), 'doctype', scrub(dt), scrub(dt))) \
		+ '\n' + (dt_details[0][1] or '')
		
	# compile for import
	if code.strip():
		import re
		p = re.compile('\$import\( (?P<name> [^)]*) \)', re.VERBOSE)
	
		code = p.sub(sub_get_doctype_js, code)

	return code
Beispiel #39
0
def add_code(doctype, doclist):
	import os, conf
	from webnotes.modules import scrub, get_module_path
	
	doc = doclist[0]
	
	path = os.path.join(get_module_path(doc.module), 'doctype', scrub(doc.name))

	def _add_code(fname, fieldname):
		fpath = os.path.join(path, fname)
		if os.path.exists(fpath):
			with open(fpath, 'r') as f:
				doc.fields[fieldname] = f.read()
		
	_add_code(scrub(doc.name) + '.js', '__js')
	_add_code(scrub(doc.name) + '.css', '__css')
	_add_code('%s_list.js' % scrub(doc.name), '__listjs')
	add_embedded_js(doc)
Beispiel #40
0
def create_folder(module, dt, dn):
	import webnotes, os
	
	# get module path by importing the module
	modules_path = get_module_path(module)
			
	code_type = dt in ['DocType', 'Page', 'Search Criteria']
	
	# create folder
	folder = os.path.join(modules_path, code_type and scrub(dt) or dt, code_type and scrub(dn) or dn)
	
	webnotes.create_folder(folder)
	
	# create init_py_files
	if code_type:
		create_init_py(modules_path, scrub(dt), scrub(dn))
	
	return folder
def get_custom_server_script_path(doctype, plugin=None):
	from webnotes.modules import scrub, get_plugin_path
	from webnotes.utils import get_site_base_path
	import os
	
	# check if doctype exists
	opts = webnotes.conn.get_value("DocType", doctype, ["name", "module", "plugin"])
	if not opts:
		raise webnotes.DoesNotExistError("""DocType "{doctype}" does not exist""".format(doctype=doctype))
	
	name, module, doctype_plugin = opts
	if not plugin:
		plugin = doctype_plugin or os.path.basename(get_site_base_path())
	
	# site_abs_path/plugin_name/module_name/doctype/doctype_name/doctype_name.py
	path = os.path.join(get_plugin_path(scrub(plugin)), scrub(module),
		"doctype", scrub(doctype), scrub(doctype) + ".py")
		
	return path
Beispiel #42
0
def add_code(doctype, doclist):
    import os, conf
    from webnotes.modules import scrub, get_module_path

    doc = doclist[0]

    path = os.path.join(get_module_path(doc.module), 'doctype',
                        scrub(doc.name))

    def _add_code(fname, fieldname):
        fpath = os.path.join(path, fname)
        if os.path.exists(fpath):
            with open(fpath, 'r') as f:
                doc.fields[fieldname] = f.read()

    _add_code(scrub(doc.name) + '.js', '__js')
    _add_code(scrub(doc.name) + '.css', '__css')
    _add_code('%s_list.js' % scrub(doc.name), '__listjs')
    add_embedded_js(doc)
Beispiel #43
0
def change_module(dt, dn, from_module, to_module):
	import os, webnotes.defs
	from webnotes.modules import scrub
	
	# change in db
	webnotes.conn.sql("update `tab%s` set module=%s where name=%s" % (dt, '%s', '%s'), (to_module, dn))
	
	# export files
	from webnotes.modules.export_module import export_to_files
	export_to_files(record_list = [[dt, dn]])
	
	if dt in ['DocType','Page','Search Criteria']:
		dt, dn = scrub(dt), scrub(dn)
		
	# svn add
	webnotes.msgprint(os.popen("svn add %s" % os.path.join(webnotes.defs.modules_path, scrub(to_module), dt, dn)).read())

	# svn remove
	webnotes.msgprint(os.popen("svn remove %s" % os.path.join(webnotes.defs.modules_path, scrub(from_module), dt, dn)).read())
Beispiel #44
0
def get_script(report_name):
    report = webnotes.doc("Report", report_name)

    module = webnotes.conn.get_value("DocType", report.ref_doctype, "module")
    module_path = get_module_path(module)
    report_folder = os.path.join(module_path, "report", scrub(report.name))
    script_path = os.path.join(report_folder, scrub(report.name) + ".js")

    script = None
    if os.path.exists(script_path):
        with open(script_path, "r") as script:
            script = script.read()

    if not script and report.is_standard == "No":
        script = webnotes.plugins.read_file(module,
                                            "Report",
                                            report.name,
                                            extn="js",
                                            cache=True)

    if not script and report.javascript:
        script = report.javascript

    if not script:
        script = "wn.query_reports['%s']={}" % report_name

    # load translations
    if webnotes.lang != "en":
        from webnotes.translate import get_lang_data
        if os.path.exists(report_folder):
            messages = get_lang_data(report_folder, webnotes.lang, 'js')
            webnotes.response["__messages"] = messages
        else:
            # TODO check if language files get exported here
            plugins_report_folder = webnotes.plugins.get_path(
                module, "Report", report.name)
            if os.path.exists(plugins_report_folder):
                messages = get_lang_data(plugins_report_folder, webnotes.lang,
                                         'js')
                webnotes.response["__messages"] = messages

    return script
Beispiel #45
0
	def make_controller_template(self):
		from webnotes.modules import get_doc_path, get_module_path, scrub
		
		pypath = os.path.join(get_doc_path(self.doc.module, 
			self.doc.doctype, self.doc.name), scrub(self.doc.name) + '.py')

		if not os.path.exists(pypath):
			with open(pypath, 'w') as pyfile:
				with open(os.path.join(get_module_path("core"), "doctype", "doctype", 
					"doctype_template.py"), 'r') as srcfile:
					pyfile.write(srcfile.read())
Beispiel #46
0
	def make_controller_template(self):
		from webnotes.modules import get_doc_path, get_module_path, scrub
		
		pypath = os.path.join(get_doc_path(self.doc.module, 
			self.doc.doctype, self.doc.name), scrub(self.doc.name) + '.py')

		if not os.path.exists(pypath):
			with open(pypath, 'w') as pyfile:
				with open(os.path.join(get_module_path("core"), "doctype", "doctype", 
					"doctype_template.py"), 'r') as srcfile:
					pyfile.write(srcfile.read())
Beispiel #47
0
	def onload(self):
		import os
		from webnotes.modules import get_module_path, scrub
		
		# load content
		try:
			file = open(os.path.join(get_module_path(self.doc.module), 'page', scrub(self.doc.name) + '.html'), 'r')
			self.doc.content = file.read() or ''
			file.close()
		except IOError, e: # no file / permission
			if e.args[0]!=2:
				raise e
Beispiel #48
0
	def on_update(self):
		from webnotes.model.db_schema import updatedb
		updatedb(self.doc.name)

		self.change_modified_of_parent()
		
		import conf
		if (not webnotes.in_import) and getattr(conf, 'developer_mode', 0):
			self.export_doc()
			self.make_controller_template()
		
		# update index
		if not self.doc.custom:
			from webnotes.modules import scrub
			doctype = scrub(self.doc.name)
			module = __import__(scrub(self.doc.module) + ".doctype." + doctype + "." + doctype,
				fromlist=[""])
			if hasattr(module, "on_doctype_update"):
				module.on_doctype_update()
		
		webnotes.clear_cache(doctype=self.doc.name)
Beispiel #49
0
    def on_update(self):
        from webnotes.model.db_schema import updatedb
        updatedb(self.doc.name)

        self.change_modified_of_parent()

        import conf
        if (not webnotes.in_import) and getattr(conf, 'developer_mode', 0):
            self.export_doc()
            self.make_controller_template()

        # update index
        if not self.doc.custom:
            from webnotes.modules import scrub
            doctype = scrub(self.doc.name)
            module = __import__(scrub(self.doc.module) + ".doctype." +
                                doctype + "." + doctype,
                                fromlist=[""])
            if hasattr(module, "on_doctype_update"):
                module.on_doctype_update()

        webnotes.clear_cache(doctype=self.doc.name)
Beispiel #50
0
def create_folder(module, dt, dn):
    """
		Creates directories for module and their __init__.py
	"""
    import webnotes, os

    # get module path by importing the module
    modules_path = get_module_path(module)

    code_type = dt in ['DocType', 'Page', 'Search Criteria']

    # create folder
    folder = os.path.join(modules_path, code_type and scrub(dt) or dt,
                          code_type and scrub(dn) or dn)

    webnotes.create_folder(folder)

    # create init_py_files
    if code_type:
        create_init_py(modules_path, scrub(dt), scrub(dn))

    return folder
def write_document_file(doclist, record_module=None):
    from webnotes.modules.utils import pprint_doclist

    doclist = [filter_fields(d.fields) for d in doclist]

    module = record_module or get_module_name(doclist)
    code_type = doclist[0]['doctype'] in lower_case_files_for

    # create folder
    folder = create_folder(module, doclist[0]['doctype'], doclist[0]['name'],
                           code_type)

    # write the data file
    fname = (code_type and scrub(doclist[0]['name'])) or doclist[0]['name']
    with open(os.path.join(folder, fname + '.txt'), 'w+') as txtfile:
        txtfile.write(pprint_doclist(doclist))
Beispiel #52
0
	def on_update(self):
		"""
			Writes the .txt for this page and if write_content is checked,
			it will write out a .html file
		"""
		from webnotes import defs
		from webnotes.utils.transfer import in_transfer
		if not in_transfer and getattr(defs,'developer_mode', 0):
			from webnotes.modules.export_module import export_to_files
			from webnotes.modules import get_module_path, scrub
			import os
			export_to_files(record_list=[['Page', self.doc.name]])
	
			if self.doc.write_content and self.doc.content:
				file = open(os.path.join(get_module_path(self.doc.module), 'page', scrub(self.doc.name), scrub(self.doc.name) + '.html'), 'w')
				file.write(self.doc.content)
				file.close()
Beispiel #53
0
	def onload(self):
		"""
			loads html from file before passing
		"""
		import os
		from webnotes.modules import get_module_path, scrub
		
		# load content
		if not self.doc.module:
			return
			
		try:
			file = open(os.path.join(get_module_path(self.doc.module), 'page', scrub(self.doc.name) + '.html'), 'r')
			self.doc.content = file.read() or ''
			file.close()
		except IOError, e: # no file / permission
			if e.args[0]!=2:
				raise e
Beispiel #54
0
def create_folder(module, dt, dn, code_type, plugin=None):
    if plugin:
        module_path = os.path.join(get_plugin_path(plugin), scrub(module))
    else:
        module_path = get_module_path(module)

    dt, dn = scrub_dt_dn(dt, dn)

    # create folder
    folder = os.path.join(module_path, dt, dn)

    webnotes.create_folder(folder)

    # create init_py_files
    if code_type:
        create_init_py(module_path, dt, dn)

    return folder
Beispiel #55
0
def switch_module(dt, dn, to, frm=None, export=None):
    """
		Change the module of the given doctype, if export is true, then also export txt and copy
		code files from src
	"""
    webnotes.conn.sql("update `tab" + dt + "` set module=%s where name=%s",
                      (to, dn))

    if export:
        export_doc(dt, dn)

        # copy code files
        if dt in ('DocType', 'Page', 'Report'):
            from_path = os.path.join(get_module_path(frm), scrub(dt),
                                     scrub(dn), scrub(dn))
            to_path = os.path.join(get_module_path(to), scrub(dt), scrub(dn),
                                   scrub(dn))

            # make dire if exists
            os.system('mkdir -p %s' %
                      os.path.join(get_module_path(to), scrub(dt), scrub(dn)))

            for ext in ('py', 'js', 'html', 'css'):
                os.system('cp %s %s')
Beispiel #56
0
def import_defaults():
    records = [
        # item group
        {
            'doctype': 'Item Group',
            'item_group_name': 'All Item Groups',
            'is_group': 'Yes',
            'parent_item_group': ''
        },
        {
            'doctype': 'Item Group',
            'item_group_name': 'Products',
            'is_group': 'No',
            'parent_item_group': 'All Item Groups'
        },
        {
            'doctype': 'Item Group',
            'item_group_name': 'Raw Material',
            'is_group': 'No',
            'parent_item_group': 'All Item Groups'
        },
        {
            'doctype': 'Item Group',
            'item_group_name': 'Services',
            'is_group': 'No',
            'parent_item_group': 'All Item Groups'
        },
        {
            'doctype': 'Item Group',
            'item_group_name': 'Sub Assemblies',
            'is_group': 'No',
            'parent_item_group': 'All Item Groups'
        },

        # deduction type
        {
            'doctype': 'Deduction Type',
            'name': 'Income Tax',
            'description': 'Income Tax',
            'deduction_name': 'Income Tax'
        },
        {
            'doctype': 'Deduction Type',
            'name': 'Professional Tax',
            'description': 'Professional Tax',
            'deduction_name': 'Professional Tax'
        },
        {
            'doctype': 'Deduction Type',
            'name': 'Provident Fund',
            'description': 'Provident fund',
            'deduction_name': 'Provident Fund'
        },

        # earning type
        {
            'doctype': 'Earning Type',
            'name': 'Basic',
            'description': 'Basic',
            'earning_name': 'Basic',
            'taxable': 'Yes'
        },
        {
            'doctype': 'Earning Type',
            'name': 'House Rent Allowance',
            'description': 'House Rent Allowance',
            'earning_name': 'House Rent Allowance',
            'taxable': 'No'
        },

        # expense claim type
        {
            'doctype': 'Expense Claim Type',
            'name': 'Calls',
            'expense_type': 'Calls'
        },
        {
            'doctype': 'Expense Claim Type',
            'name': 'Food',
            'expense_type': 'Food'
        },
        {
            'doctype': 'Expense Claim Type',
            'name': 'Medical',
            'expense_type': 'Medical'
        },
        {
            'doctype': 'Expense Claim Type',
            'name': 'Others',
            'expense_type': 'Others'
        },
        {
            'doctype': 'Expense Claim Type',
            'name': 'Travel',
            'expense_type': 'Travel'
        },

        # leave type
        {
            'doctype': 'Leave Type',
            'leave_type_name': 'Casual Leave',
            'name': 'Casual Leave',
            'is_encash': 1,
            'is_carry_forward': 1,
            'max_days_allowed': '3',
        },
        {
            'doctype': 'Leave Type',
            'leave_type_name': 'Compensatory Off',
            'name': 'Compensatory Off',
            'is_encash': 0,
            'is_carry_forward': 0,
        },
        {
            'doctype': 'Leave Type',
            'leave_type_name': 'Sick Leave',
            'name': 'Sick Leave',
            'is_encash': 0,
            'is_carry_forward': 0,
        },
        {
            'doctype': 'Leave Type',
            'leave_type_name': 'Privilege Leave',
            'name': 'Privilege Leave',
            'is_encash': 0,
            'is_carry_forward': 0,
        },
        {
            'doctype': 'Leave Type',
            'leave_type_name': 'Leave Without Pay',
            'name': 'Leave Without Pay',
            'is_encash': 0,
            'is_carry_forward': 0,
            'is_lwp': 1
        },

        # territory
        {
            'doctype': 'Territory',
            'territory_name': 'All Territories',
            'is_group': 'Yes',
            'name': 'All Territories',
            'parent_territory': ''
        },

        # customer group
        {
            'doctype': 'Customer Group',
            'customer_group_name': 'All Customer Groups',
            'is_group': 'Yes',
            'name': 'All Customer Groups',
            'parent_customer_group': ''
        },
        {
            'doctype': 'Customer Group',
            'customer_group_name': 'Individual',
            'is_group': 'No',
            'parent_customer_group': 'All Customer Groups'
        },
        {
            'doctype': 'Customer Group',
            'customer_group_name': 'Commercial',
            'is_group': 'No',
            'parent_customer_group': 'All Customer Groups'
        },
        {
            'doctype': 'Customer Group',
            'customer_group_name': 'Non Profit',
            'is_group': 'No',
            'parent_customer_group': 'All Customer Groups'
        },
        {
            'doctype': 'Customer Group',
            'customer_group_name': 'Government',
            'is_group': 'No',
            'parent_customer_group': 'All Customer Groups'
        },

        # supplier type
        {
            'doctype': 'Supplier Type',
            'supplier_type': 'Services'
        },
        {
            'doctype': 'Supplier Type',
            'supplier_type': 'Local'
        },
        {
            'doctype': 'Supplier Type',
            'supplier_type': 'Raw Material'
        },
        {
            'doctype': 'Supplier Type',
            'supplier_type': 'Electrical'
        },
        {
            'doctype': 'Supplier Type',
            'supplier_type': 'Hardware'
        },
        {
            'doctype': 'Supplier Type',
            'supplier_type': 'Pharmaceutical'
        },
        {
            'doctype': 'Supplier Type',
            'supplier_type': 'Distributor'
        },

        # Sales Person
        {
            'doctype': 'Sales Person',
            'sales_person_name': 'Sales Team',
            'is_group': "Yes",
            "parent_sales_person": ""
        },

        # UOM
        {
            'uom_name': 'Unit',
            'doctype': 'UOM',
            'name': 'Unit',
            "must_be_whole_number": 1
        },
        {
            'uom_name': 'Box',
            'doctype': 'UOM',
            'name': 'Box',
            "must_be_whole_number": 1
        },
        {
            'uom_name': 'Kg',
            'doctype': 'UOM',
            'name': 'Kg'
        },
        {
            'uom_name': 'Nos',
            'doctype': 'UOM',
            'name': 'Nos',
            "must_be_whole_number": 1
        },
        {
            'uom_name': 'Pair',
            'doctype': 'UOM',
            'name': 'Pair',
            "must_be_whole_number": 1
        },
        {
            'uom_name': 'Set',
            'doctype': 'UOM',
            'name': 'Set',
            "must_be_whole_number": 1
        },
        {
            'uom_name': 'Hour',
            'doctype': 'UOM',
            'name': 'Hour'
        },
        {
            'uom_name': 'Minute',
            'doctype': 'UOM',
            'name': 'Minute'
        },
    ]

    from webnotes.modules import scrub
    for r in records:
        bean = webnotes.bean(r)

        # ignore mandatory for root
        parent_link_field = ("parent_" + scrub(bean.doc.doctype))
        if parent_link_field in bean.doc.fields and not bean.doc.fields.get(
                parent_link_field):
            bean.ignore_mandatory = True

        bean.insert()
Beispiel #57
0
def get_doctypes(m):
    doctypes = webnotes.conn.sql_list(
        """select name from 
		tabDocType where module=%s order by name""", m)
    prefix = "docs.dev.modules." + m + ".doctype."
    docs = {
        "_icon": "th",
        "_label": "DocTypes",
        "_toc": [prefix + d for d in doctypes]
    }

    for d in doctypes:
        meta = webnotes.get_doctype(d)
        meta_p = webnotes.get_doctype(d, True)
        doc_path = get_doc_path(m, "DocType", d)

        mydocs = docs[d] = {
            "_label":
            d,
            "_icon":
            meta[0].icon,
            "_type":
            "doctype",
            "_gh_source":
            get_gh_url(doc_path),
            "_toc": [
                prefix + d + ".model", prefix + d + ".permissions",
                prefix + d + ".controller_server"
            ],
        }

        update_readme(mydocs, m, "DocType", d)

        # parents and links
        links, parents = [], []
        for df in webnotes.conn.sql(
                """select * from tabDocField where options=%s""", d,
                as_dict=True):
            if df.parent:
                if df.fieldtype == "Table":
                    parents.append(df.parent)
                if df.fieldtype == "Link":
                    links.append(df.parent)

        if parents:
            mydocs["_intro"] += "\n\n#### Child Table Of:\n\n- " + "\n- ".join(
                list(set(parents))) + "\n\n"

        if links:
            mydocs["_intro"] += "\n\n#### Linked In:\n\n- " + "\n- ".join(
                list(set(links))) + "\n\n"

        if meta[0].issingle:
            mydocs[
                "_intro"] += "\n\n#### Single DocType\n\nThere is no table for this DocType and the values of the Single instance are stored in `tabSingles`"

        # model
        modeldocs = mydocs["model"] = {
            "_label": d + " Model",
            "_icon": meta[0].icon,
            "_type": "model",
            "_intro": "Properties and fields for " + d,
            "_gh_source": get_gh_url(os.path.join(doc_path,
                                                  scrub(d) + ".txt")),
            "_fields": [df.fields for df in meta.get({"doctype": "DocField"})],
            "_properties": meta[0].fields,
            "_modified": meta[0].modified
        }

        # permissions
        from webnotes.modules.utils import peval_doclist
        with open(os.path.join(doc_path, scrub(d) + ".txt"), "r") as txtfile:
            doclist = peval_doclist(txtfile.read())

        permission_docs = mydocs["permissions"] = {
            "_label": d + " Permissions",
            "_type": "permissions",
            "_icon": meta[0].icon,
            "_gh_source": get_gh_url(os.path.join(doc_path,
                                                  scrub(d) + ".txt")),
            "_intro": "Standard Permissions for " + d +
            ". These can be changed by the user.",
            "_permissions": [p for p in doclist if p.doctype == "DocPerm"],
            "_modified": doclist[0]["modified"]
        }

        # server controller
        server_controller_path = os.path.join(doc_path, scrub(d) + ".py")
        controller_docs = mydocs["controller_server"] = {
            "_label": d + " Server Controller",
            "_type": "_class",
            "_gh_source": get_gh_url(server_controller_path)
        }

        b = webnotes.bean([{"doctype": d}])
        b.make_controller()
        if not getattr(b.controller, "__doc__"):
            b.controller.__doc__ = "Controller Class for handling server-side events for " + d
        inspect_object_and_update_docs(controller_docs, b.controller)

        # client controller
        if meta_p[0].fields.get("__js"):
            client_controller_path = os.path.join(doc_path, scrub(d) + ".js")
            if (os.path.exists(client_controller_path)):
                mydocs["_toc"].append(prefix + d + ".controller_client")
                client_controller = mydocs["controller_client"] = {
                    "_label":
                    d + " Client Controller",
                    "_icon":
                    meta[0].icon,
                    "_type":
                    "controller_client",
                    "_gh_source":
                    get_gh_url(client_controller_path),
                    "_modified":
                    get_timestamp(client_controller_path),
                    "_intro":
                    "Client side triggers and functions for " + d,
                    "_code":
                    meta_p[0].fields["__js"],
                    "_fields":
                    [d.fieldname for d in meta_p if d.doctype == "DocField"]
                }

    return docs