Esempio n. 1
0
def execute_patch(patchmodule, method=None, methodargs=None):
    """execute the patch"""
    success = False
    block_user(True)
    webnotes.conn.begin()
    try:
        log('Executing %s in %s' %
            (patchmodule or str(methodargs), webnotes.conn.cur_db_name))
        if patchmodule:
            if patchmodule.startswith("execute:"):
                exec patchmodule.split("execute:")[1] in globals()
            else:
                webnotes.get_method(patchmodule + ".execute")()
            update_patch_log(patchmodule)
        elif method:
            method(**methodargs)

        webnotes.conn.commit()
        success = True
    except Exception, e:
        webnotes.conn.rollback()
        global has_errors
        has_errors = True
        tb = webnotes.getTraceback()
        log(tb)
        import os
        if os.environ.get('HTTP_HOST'):
            add_to_patch_log(tb)
Esempio n. 2
0
def execute_patch(patchmodule, method=None, methodargs=None):
	"""execute the patch"""
	success = False
	block_user(True)
	webnotes.conn.begin()
	try:
		log('Executing %s in %s' % (patchmodule or str(methodargs), webnotes.conn.cur_db_name))
		if patchmodule:
			if patchmodule.startswith("execute:"):
				exec patchmodule.split("execute:")[1] in globals()
			else:
				webnotes.get_method(patchmodule + ".execute")()
			update_patch_log(patchmodule)
		elif method:
			method(**methodargs)
			
		webnotes.conn.commit()
		success = True
	except Exception, e:
		webnotes.conn.rollback()
		global has_errors
		has_errors = True
		tb = webnotes.getTraceback()
		log(tb)
		import os
		if os.environ.get('HTTP_HOST'):
			add_to_patch_log(tb)
Esempio n. 3
0
 def call_observers(key):
     if key in observer_map:
         observer_list = observer_map[key]
         if isinstance(observer_list, basestring):
             observer_list = [observer_list]
         for observer_method in observer_list:
             webnotes.get_method(observer_method)(controller, caller_method)
Esempio n. 4
0
	def call_observers(key):
		if key in observer_map:
			observer_list = observer_map[key]
			if isinstance(observer_list, basestring):
				observer_list = [observer_list]
			for observer_method in observer_list:
				webnotes.get_method(observer_method)(controller, caller_method)
Esempio n. 5
0
def prepare_args(page_name):
	if page_name == 'index':
		page_name = get_home_page()
	
	if page_name in get_template_pages():
		args = webnotes._dict({
			'template': 'pages/%s.html' % page_name,
			'name': page_name,
		})
		if page_name in page_settings_map:
			target = page_settings_map[page_name]
			if "." in target:
				args.update(webnotes.get_method(target)())
			else:
				args.obj = webnotes.bean(page_settings_map[page_name]).obj

	else:
		args = get_doc_fields(page_name)
	
	if not args:
		return False
	
	get_outer_env(page_name, args)
	
	return args	
Esempio n. 6
0
def get_method(cmd):
    """get method object from cmd"""
    if '.' in cmd:
        method = webnotes.get_method(cmd)
    else:
        method = globals()[cmd]
    return method
Esempio n. 7
0
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
	}
Esempio n. 8
0
def search_widget(doctype, txt, query=None, searchfield="name", start=0, page_len=50, filters=None):
	if isinstance(filters, basestring):
		import json
		filters = json.loads(filters)
		
	if query and query.split()[0].lower()!="select":
		webnotes.response["values"] = webnotes.get_method(query)(doctype, txt, 
			searchfield, start, page_len, filters)
	elif not query and doctype in standard_queries:
		search_widget(doctype, txt, standard_queries[doctype], 
			searchfield, start, page_len, filters)
	else:
		if query:
			webnotes.response["values"] = webnotes.conn.sql(scrub_custom_query(query, 
				searchfield, txt))
		else:
			if filters:
				webnotes.response["values"] = get_query_result(
					', '.join(get_std_fields_list(doctype, searchfield)), doctype, txt, 
					searchfield, start, page_len, filters)
			else:
				query = make_query(', '.join(get_std_fields_list(doctype, searchfield)), doctype, 
					searchfield, txt, start, page_len)

				webnotes.widgets.query_builder.runquery(query)
Esempio n. 9
0
def get_method(cmd):
	"""get method object from cmd"""
	if '.' in cmd:
		method = webnotes.get_method(cmd)
	else:
		method = globals()[cmd]
	return method
Esempio n. 10
0
def prepare_args(page_name):
    if page_name == 'index':
        page_name = get_home_page()

    pages = get_page_settings()

    if page_name in pages:
        page_info = pages[page_name]
        args = webnotes._dict({
            'template': page_info["template"],
            'name': page_name,
        })

        # additional args
        if "args_method" in page_info:
            args.update(webnotes.get_method(page_info["args_method"])())
        elif "args_doctype" in page_info:
            bean = webnotes.bean(page_info["args_doctype"])
            bean.run_method("onload")
            args.obj = bean.make_controller()

    else:
        args = get_doc_fields(page_name)

    if not args:
        return False

    update_template_args(page_name, args)

    return args
Esempio n. 11
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
	}
Esempio n. 12
0
def search_widget(doctype,
                  txt,
                  query=None,
                  searchfield="name",
                  start=0,
                  page_len=50,
                  filters=None):
    if isinstance(filters, basestring):
        import json
        filters = json.loads(filters)

    if query and query.split()[0].lower() != "select":
        webnotes.response["values"] = webnotes.get_method(query)(doctype, txt,
                                                                 searchfield,
                                                                 start,
                                                                 page_len,
                                                                 filters)
    elif not query and doctype in standard_queries:
        search_widget(doctype, txt, standard_queries[doctype], searchfield,
                      start, page_len, filters)
    else:
        if query:
            webnotes.response["values"] = webnotes.conn.sql(
                scrub_custom_query(query, searchfield, txt))
        else:
            if filters:
                webnotes.response["values"] = get_query_result(
                    ', '.join(get_std_fields_list(doctype, searchfield)),
                    doctype, txt, searchfield, start, page_len, filters)
            else:
                query = make_query(
                    ', '.join(get_std_fields_list(doctype, searchfield)),
                    doctype, searchfield, txt, start, page_len)

                webnotes.widgets.query_builder.runquery(query)
Esempio n. 13
0
def prepare_args(page_name):
	if page_name == 'index':
		page_name = get_home_page()
	
	pages = get_page_settings()
	
	if page_name in pages:
		page_info = pages[page_name]
		args = webnotes._dict({
			'template': page_info["template"],
			'name': page_name,
		})

		# additional args
		if "args_method" in page_info:
			args.update(webnotes.get_method(page_info["args_method"])())
		elif "args_doctype" in page_info:
			args.obj = webnotes.bean(page_info["args_doctype"]).obj

	else:
		args = get_doc_fields(page_name)
	
	if not args:
		return False
	
	update_template_args(page_name, args)
	
	return args	
Esempio n. 14
0
def get_method(cmd):
    """get method object from cmd"""
    if "." in cmd:
        method = webnotes.get_method(cmd)
    else:
        method = globals()[cmd]
    webnotes.log("method:" + cmd)
    return method
Esempio n. 15
0
def uploadfile():
	import webnotes.utils
	import webnotes.utils.file_manager
	import json

	ret = []

	try:
		if webnotes.form_dict.get('from_form'):
			webnotes.utils.file_manager.upload()
		else:
			if webnotes.form_dict.get('method'):
				ret = webnotes.get_method(webnotes.form_dict.method)()
	except Exception, e:
		webnotes.msgprint(e)
		webnotes.errprint(webnotes.utils.getTraceback())
Esempio n. 16
0
def uploadfile():
    import webnotes.utils
    import webnotes.utils.file_manager
    import json

    ret = []

    try:
        if webnotes.form_dict.get('from_form'):
            webnotes.utils.file_manager.upload()
        else:
            if webnotes.form_dict.get('method'):
                ret = webnotes.get_method(webnotes.form_dict.method)()
    except Exception, e:
        webnotes.msgprint(e)
        webnotes.errprint(webnotes.utils.getTraceback())
Esempio n. 17
0
def search_widget(doctype, txt, query=None, searchfield="name", start=0, 
	page_len=50, filters=None):
	if isinstance(filters, basestring):
		import json
		filters = json.loads(filters)

	meta = webnotes.get_doctype(doctype)
	
	if query and query.split()[0].lower()!="select":
		# by method
		webnotes.response["values"] = webnotes.get_method(query)(doctype, txt, 
			searchfield, start, page_len, filters)
	elif startup_standard_queries and not query and doctype in standard_queries:
		# from standard queries
		search_widget(doctype, txt, standard_queries[doctype], 
			searchfield, start, page_len, filters)
	else:
		if query:
			# custom query
			webnotes.response["values"] = webnotes.conn.sql(scrub_custom_query(query, 
				searchfield, txt))
		else:
			if isinstance(filters, dict):
				filters_items = filters.items()
				filters = []
				for f in filters_items:
					if isinstance(f[1], (list, tuple)):
						filters.append([doctype, f[0], f[1][0], f[1][1]])
					else:
						filters.append([doctype, f[0], "=", f[1]])

			if filters==None:
				filters = []
			
			# build from doctype
			if txt:
				filters.append([doctype, searchfield or "name", "like", txt + "%"])
			if meta.get({"parent":doctype, "fieldname":"enabled", "fieldtype":"Check"}):
				filters.append([doctype, "enabled", "=", 1])
			if meta.get({"parent":doctype, "fieldname":"disabled", "fieldtype":"Check"}):
				filters.append([doctype, "disabled", "!=", 1])

			webnotes.response["values"] = webnotes.widgets.reportview.execute(doctype,
				filters=filters, fields = get_std_fields_list(meta, searchfield or "name"), 
				limit_start = start, limit_page_length=page_len, as_list=True)
Esempio n. 18
0
def prepare_args(page_name):

	has_app = True
	try:
		from startup.webutils import update_template_args, get_home_page
	except ImportError:
		has_app = False

	if page_name == 'index':
		if has_app:
			page_name = get_home_page()
		else:
			page_name = "login"
	
	pages = get_page_settings()
	
	if page_name in pages:
		page_info = pages[page_name]
		args = webnotes._dict({
			'template': page_info["template"],
			'name': page_name,
		})

		# additional args
		if "args_method" in page_info:
			args.update(webnotes.get_method(page_info["args_method"])())
		elif "args_doctype" in page_info:
			bean = webnotes.bean(page_info["args_doctype"])
			bean.run_method("onload")
			args.obj = bean.make_controller()
	else:
		args = get_doc_fields(page_name)
	
	if not args:
		return False
	
	if has_app:
		args = update_template_args(page_name, args)
	
	return args	
Esempio n. 19
0
def uploadfile():
    import webnotes.utils
    import webnotes.utils.file_manager
    import json

    try:
        if webnotes.form_dict.get('from_form'):
            try:
                ret = webnotes.utils.file_manager.upload()
            except webnotes.DuplicateEntryError, e:
                # ignore pass
                ret = None
                webnotes.conn.rollback()
        else:
            if webnotes.form_dict.get('method'):
                ret = webnotes.get_method(webnotes.form_dict.method)()
    except Exception, e:
        webnotes.errprint(webnotes.utils.getTraceback())
        ret = None

    return ret


def handle():
    """handle request"""
    cmd = webnotes.form_dict['cmd']

    if cmd != 'login':
        # login executed in webnotes.auth
        if webnotes.request_method == "POST":
            webnotes.conn.begin()
Esempio n. 20
0
def uploadfile():
	import webnotes.utils
	import webnotes.utils.file_manager
	import json

	try:
		if webnotes.form_dict.get('from_form'):
			try:
				ret = webnotes.utils.file_manager.upload()
			except webnotes.DuplicateEntryError, e:
				# ignore pass
				ret = None
				webnotes.conn.rollback()
		else:
			if webnotes.form_dict.get('method'):
				ret = webnotes.get_method(webnotes.form_dict.method)()
	except Exception, e:
		webnotes.errprint(webnotes.utils.getTraceback())
		ret = None

	return ret

def handle():
	"""handle request"""
	cmd = webnotes.form_dict['cmd']

	if cmd!='login':
		# login executed in webnotes.auth
		if webnotes.request_method == "POST":
			webnotes.conn.begin()