[minor] allow method object to return its own response object
This commit is contained in:
parent
3581ad8db7
commit
65730d7bcf
5 changed files with 27 additions and 11 deletions
|
|
@ -10,13 +10,22 @@ import frappe.sessions
|
|||
import frappe.utils.file_manager
|
||||
import frappe.desk.form.run_method
|
||||
from frappe.utils.response import build_response
|
||||
from werkzeug.wrappers import Response
|
||||
|
||||
def handle():
|
||||
"""handle request"""
|
||||
cmd = frappe.local.form_dict.cmd
|
||||
|
||||
if cmd!='login':
|
||||
execute_cmd(cmd)
|
||||
data = execute_cmd(cmd)
|
||||
|
||||
if data:
|
||||
if isinstance(data, Response):
|
||||
# method returns a response object, pass it on
|
||||
return data
|
||||
|
||||
# add the response to `message` label
|
||||
frappe.response['message'] = data
|
||||
|
||||
return build_response("json")
|
||||
|
||||
|
|
@ -39,11 +48,8 @@ def execute_cmd(cmd, from_async=False):
|
|||
|
||||
is_whitelisted(method)
|
||||
|
||||
ret = frappe.call(method, **frappe.form_dict)
|
||||
return frappe.call(method, **frappe.form_dict)
|
||||
|
||||
# returns with a message
|
||||
if ret:
|
||||
frappe.response['message'] = ret
|
||||
|
||||
def is_whitelisted(method):
|
||||
# check if whitelisted
|
||||
|
|
|
|||
|
|
@ -497,6 +497,10 @@ h6.uppercase,
|
|||
}
|
||||
.frappe-control pre {
|
||||
white-space: pre-wrap;
|
||||
background-color: inherit;
|
||||
border: none;
|
||||
padding: 0px;
|
||||
margin: 0px;
|
||||
}
|
||||
.hide-control {
|
||||
display: none !important;
|
||||
|
|
|
|||
|
|
@ -153,8 +153,9 @@ $(window).on('hashchange', function() {
|
|||
return;
|
||||
|
||||
// hide open dialog
|
||||
if(cur_dialog && cur_dialog.hide_on_page_refresh)
|
||||
if(cur_dialog && cur_dialog.hide_on_page_refresh) {
|
||||
cur_dialog.hide();
|
||||
}
|
||||
|
||||
frappe.route();
|
||||
|
||||
|
|
|
|||
|
|
@ -60,6 +60,12 @@ frappe.socket = {
|
|||
if (frappe.flags.doc_subscribe) {
|
||||
return;
|
||||
}
|
||||
|
||||
frappe.flags.doc_subscribe = true;
|
||||
|
||||
// throttle to 1 per sec
|
||||
setTimeout(function() { frappe.flags.doc_subscribe = false }, 1000);
|
||||
|
||||
if (frm.is_new()) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -72,11 +78,6 @@ frappe.socket = {
|
|||
}
|
||||
}
|
||||
|
||||
frappe.flags.doc_subscribe = true;
|
||||
|
||||
// throttle to 1 per sec
|
||||
setTimeout(function() { frappe.flags.doc_subscribe = false }, 1000);
|
||||
|
||||
frappe.socket.doc_subscribe(frm.doctype, frm.docname);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -625,6 +625,10 @@ h6.uppercase, .h6.uppercase {
|
|||
|
||||
pre {
|
||||
white-space: pre-wrap;
|
||||
background-color: inherit;
|
||||
border: none;
|
||||
padding: 0px;
|
||||
margin: 0px;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue