From f41f219c33344acfe2e862c357f895637650367c Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 5 Feb 2014 18:08:56 +0530 Subject: [PATCH] fixes to api --- webnotes/api.py | 14 +++++++------- webnotes/model/bean.py | 8 +++++--- webnotes/utils/response.py | 5 +++-- webnotes/widgets/reportview.py | 2 +- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/webnotes/api.py b/webnotes/api.py index 7305bf6618..6a20402d04 100644 --- a/webnotes/api.py +++ b/webnotes/api.py @@ -48,14 +48,12 @@ def handle(): if webnotes.local.request.method=="GET": if not bean.has_permission("read"): webnotes.throw("No Permission", webnotes.PermissionError) - webnotes.local.response.update({"data": bean.run_method(webnotes.local.form_dict.run_method, - **webnotes.local.form_dict)}) + bean.run_method(webnotes.local.form_dict.run_method, **webnotes.local.form_dict) if webnotes.local.request.method=="POST": if not bean.has_permission("write"): webnotes.throw("No Permission", webnotes.PermissionError) - webnotes.local.response.update({"data":bean.run_method(webnotes.local.form_dict.run_method, - **webnotes.local.form_dict)}) + bean.run_method(webnotes.local.form_dict.run_method, **webnotes.local.form_dict) webnotes.conn.commit() else: @@ -86,11 +84,13 @@ def handle(): doctype, **webnotes.local.form_dict)}) else: - raise Exception("Bad API") + raise webnotes.DoesNotExistError else: - raise Exception("Bad API") - + raise webnotes.DoesNotExistError + + except webnotes.DoesNotExistError, e: + report_error(404) except Exception, e: report_error(500) diff --git a/webnotes/model/bean.py b/webnotes/model/bean.py index 2d96e9de23..3ba403082f 100644 --- a/webnotes/model/bean.py +++ b/webnotes/model/bean.py @@ -229,9 +229,11 @@ class Bean: out.update(new_response) if hasattr(self.controller, method): - add_to_response(webnotes.local.response, webnotes.call(getattr(self.controller, method), *args, **kwargs)) + add_to_response(webnotes.local.response, + webnotes.call(getattr(self.controller, method), *args, **kwargs)) if hasattr(self.controller, 'custom_' + method): - add_to_response(webnotes.local.response, webnotes.call(getattr(self.controller, 'custom_' + method), *args, **kwargs)) + add_to_response(webnotes.local.response, + webnotes.call(getattr(self.controller, 'custom_' + method), *args, **kwargs)) args = [self, method] + args for handler in webnotes.get_hooks("bean_event:" + self.doc.doctype + ":" + method) \ @@ -239,7 +241,7 @@ class Bean: add_to_response(webnotes.local.response, webnotes.call(webnotes.get_attr(handler), *args, **kwargs)) self.set_doclist(self.controller.doclist) - + return webnotes.local.response def get_attr(self, method): diff --git a/webnotes/utils/response.py b/webnotes/utils/response.py index 4e80d38e3a..75f4bb2c0b 100644 --- a/webnotes/utils/response.py +++ b/webnotes/utils/response.py @@ -2,7 +2,7 @@ # MIT License. See license.txt from __future__ import unicode_literals -import json, inspect +import json import datetime import gzip, cStringIO import webnotes @@ -12,7 +12,8 @@ import webnotes.model.utils from werkzeug.local import LocalProxy def report_error(status_code): - webnotes.errprint(webnotes.utils.get_traceback()) + if status_code!=404: + webnotes.errprint(webnotes.utils.get_traceback()) webnotes._response.status_code = status_code if webnotes.request_method == "POST": webnotes.conn.rollback() diff --git a/webnotes/widgets/reportview.py b/webnotes/widgets/reportview.py index fec1641bea..f3f09cc2cd 100644 --- a/webnotes/widgets/reportview.py +++ b/webnotes/widgets/reportview.py @@ -27,7 +27,7 @@ def get_form_params(): return data def execute(doctype, query=None, filters=None, fields=None, docstatus=None, - group_by=None, order_by=None, limit_start=0, limit_page_length=None, + group_by=None, order_by=None, limit_start=0, limit_page_length=20, as_list=False, with_childnames=False, debug=False): """