Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added method_decorators into rest api resources #991

Merged
merged 6 commits into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions aiida/restapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def error_handler(error):
else:
pass


class AiidaApi(Api):
"""
AiiDA customized version of the flask_restful Api class
Expand Down Expand Up @@ -306,7 +305,6 @@ 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
Expand Down Expand Up @@ -336,3 +334,4 @@ def handle_error(self, e):

else:
raise e

18 changes: 13 additions & 5 deletions aiida/restapi/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

from aiida.restapi.common.utils import Utils


class ServerInfo(Resource):
def __init__(self, **kwargs):
# Configure utils
Expand Down Expand Up @@ -88,11 +87,15 @@ 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):
## 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
Expand All @@ -105,6 +108,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):
"""
Expand Down Expand Up @@ -173,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
Expand All @@ -192,6 +199,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', [])}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so is there a good reason why Node does not inherit from BaseResource?
The explanation below "class Node(Resource)" is not entirely clear to me, perhaps you could make it a docstring and expand it a little bit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NodeResource class is different from BaseResource in trans.set_query() mostly because it takes query_type as an input and the presence of additional result types like "tree". I have updated the doc string.


def get(self, id=None, page=None):
"""
Expand Down
2 changes: 1 addition & 1 deletion setup_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down