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

fix in custom schema (rest api) #1490

Merged
merged 4 commits into from
May 9, 2018
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
14 changes: 11 additions & 3 deletions aiida/restapi/translator/computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@ class ComputerTranslator(BaseTranslator):

_result_type = __label__

_default_projections = None

# Extract the default projections from custom_schema if they are defined
if 'columns' in custom_schema:
_default_projections = custom_schema['columns'][__label__]
else:
if custom_schema is not None:
try:
# check if schema is defined for given node type
if __label__ in custom_schema['columns'].keys():
_default_projections = custom_schema['columns'][__label__]
except KeyError:
pass

if _default_projections is None:
_default_projections = ['**']

def __init__(self, **kwargs):
Expand Down
14 changes: 11 additions & 3 deletions aiida/restapi/translator/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@ class GroupTranslator(BaseTranslator):

_result_type = __label__

_default_projections = None

# Extract the default projections from custom_schema if they are defined
if 'columns' in custom_schema:
_default_projections = custom_schema['columns'][__label__]
else:
if custom_schema is not None:
try:
# check if schema is defined for given node type
if __label__ in custom_schema['columns'].keys():
_default_projections = custom_schema['columns'][__label__]
except KeyError:
pass

if _default_projections is None:
_default_projections = ['**']


Expand Down
15 changes: 11 additions & 4 deletions aiida/restapi/translator/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,18 @@ def __init__(self, Class=None, **kwargs):
# basic initialization
super(NodeTranslator, self).__init__(Class=Class, **kwargs)

self._default_projections = None

# Extract the default projections from custom_schema if they are defined
if self.custom_schema is not None and 'columns' in self.custom_schema:
self._default_projections = self.custom_schema['columns'][
self.__label__]
else:
if self.custom_schema is not None:
try:
# check if schema is defined for given node type
if self.__label__ in self.custom_schema['columns'].keys():
self._default_projections = self.custom_schema['columns'][self.__label__]
except KeyError:
pass

if self._default_projections is None:
self._default_projections = ['**']

# Inspect the subclasses of NodeTranslator, to avoid hard-coding
Expand Down
14 changes: 11 additions & 3 deletions aiida/restapi/translator/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@ class UserTranslator(BaseTranslator):

_result_type = __label__

_default_projections = None

# Extract the default projections from custom_schema if they are defined
if 'columns' in custom_schema:
_default_projections = custom_schema['columns'][__label__]
else:
if custom_schema is not None:
try:
# check if schema is defined for given node type
if __label__ in custom_schema['columns'].keys():
_default_projections = custom_schema['columns'][__label__]
except KeyError:
pass

if _default_projections is None:
# send only white listed keys in default response for user for security reasons
_default_projections = ['id', 'first_name', "last_name", 'institution', 'date_joined']

Expand Down