From 00d9cb82e08683a32ccd5486d4a488658203f2dc Mon Sep 17 00:00:00 2001 From: Snehal Kumbhar Date: Thu, 14 Dec 2017 11:55:51 +0100 Subject: [PATCH 1/4] Added method_decorators into resources --- aiida/restapi/api.py | 8 ++++---- aiida/restapi/resources.py | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/aiida/restapi/api.py b/aiida/restapi/api.py index 3f8c40f108..ae67d3f06a 100644 --- a/aiida/restapi/api.py +++ b/aiida/restapi/api.py @@ -74,7 +74,6 @@ def error_handler(error): else: pass - class AiidaApi(Api): """ AiiDA customized version of the flask_restful Api class @@ -306,13 +305,13 @@ def __init__(self, app=None, **kwargs): strict_slashes=False, resource_class_kwargs=kwargs) - + """ def handle_error(self, e): - """ + this method handles the 404 "URL not found" exception and return custom message :param e: raised exception :return: list of available endpoints - """ + if isinstance(e, HTTPException): if e.code == 404: @@ -336,3 +335,4 @@ def handle_error(self, e): else: raise e + """ diff --git a/aiida/restapi/resources.py b/aiida/restapi/resources.py index d167dbc32d..9f1d89d8b9 100644 --- a/aiida/restapi/resources.py +++ b/aiida/restapi/resources.py @@ -14,7 +14,6 @@ from aiida.restapi.common.utils import Utils - class ServerInfo(Resource): def __init__(self, **kwargs): # Configure utils @@ -88,6 +87,7 @@ def get(self): return self.utils.build_response(status=200, headers=headers, data=data) + ## TODO add the caching support. I cache total count, results, and possibly # set_query class BaseResource(Resource): @@ -105,6 +105,7 @@ def __init__(self, **kwargs): self.utils_confs = {k: kwargs[k] for k in utils_conf_keys if k in kwargs} self.utils = Utils(**self.utils_confs) + self.method_decorators = {'get': kwargs.get('get_decorators', [])} def get(self, id=None, page=None): """ @@ -192,6 +193,7 @@ def __init__(self, **kwargs): self.utils_confs = {k: kwargs[k] for k in utils_conf_keys if k in kwargs} self.utils = Utils(**self.utils_confs) + self.method_decorators = {'get': kwargs.get('get_decorators', [])} def get(self, id=None, page=None): """ From abee7fc255d3a72504879613c2cc7ef18a358d41 Mon Sep 17 00:00:00 2001 From: Snehal Kumbhar Date: Mon, 18 Dec 2017 15:16:19 +0100 Subject: [PATCH 2/4] handle_error enabled again --- aiida/restapi/api.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/aiida/restapi/api.py b/aiida/restapi/api.py index ae67d3f06a..c0c3999135 100644 --- a/aiida/restapi/api.py +++ b/aiida/restapi/api.py @@ -305,13 +305,12 @@ def __init__(self, app=None, **kwargs): strict_slashes=False, resource_class_kwargs=kwargs) - """ def handle_error(self, e): - + """ this method handles the 404 "URL not found" exception and return custom message :param e: raised exception :return: list of available endpoints - + """ if isinstance(e, HTTPException): if e.code == 404: @@ -335,4 +334,4 @@ def handle_error(self, e): else: raise e - """ + From d61aaab95f7c9495440a7ac31cf4d3dff63d7a28 Mon Sep 17 00:00:00 2001 From: Snehal Kumbhar Date: Tue, 19 Dec 2017 16:25:48 +0100 Subject: [PATCH 3/4] Changed flask restful version in setup_requirements --- setup_requirements.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup_requirements.py b/setup_requirements.py index a544a26104..4965521068 100644 --- a/setup_requirements.py +++ b/setup_requirements.py @@ -79,7 +79,7 @@ # Requirements for RESTful API 'REST': [ 'Flask==0.10.1', - 'Flask-RESTful==0.3.5', + 'Flask-RESTful==0.3.6', 'Flask-Cors==3.0.1', 'pyparsing==2.1.10', 'Pattern==2.6', From c05932fb94281283d79760df0aedc4fccf40108f Mon Sep 17 00:00:00 2001 From: Snehal Kumbhar Date: Tue, 19 Dec 2017 16:47:23 +0100 Subject: [PATCH 4/4] Updated doc string in base and node resource classes --- aiida/restapi/resources.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/aiida/restapi/resources.py b/aiida/restapi/resources.py index 9f1d89d8b9..096d73f33d 100644 --- a/aiida/restapi/resources.py +++ b/aiida/restapi/resources.py @@ -91,8 +91,11 @@ def get(self): ## TODO add the caching support. I cache total count, results, and possibly # set_query class BaseResource(Resource): - ## Each derived class will instantiate a different type of translator. - # This is the only difference in the classes. + """ + Each derived class will instantiate a different type of translator. + This is the only difference in the classes. + """ + def __init__(self, **kwargs): self.trans = None @@ -174,8 +177,11 @@ def get(self, id=None, page=None): class Node(Resource): - ##Differs from BaseResource in trans.set_query() mostly because it takes - # query_type as an input and the presence of "tree" result type + """ + Differs from BaseResource in trans.set_query() mostly because it takes + query_type as an input and the presence of additional result types like "tree" + """ + def __init__(self, **kwargs): # Set translator