Created
May 11, 2021 09:02
-
-
Save silenius/b412d278eb10274cbf09991992c8b938 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@view_config(request_method='GET', name='children', | |
accept='application/json') | |
def children(self): | |
schema = FolderSchema(only=('id', 'title')) | |
depth = None | |
class Encoder(json.JSONEncoder): | |
def default(self, obj): | |
if isinstance(obj, Folder): | |
return schema.dump(obj) | |
return super().default(obj) | |
result = get_children_containers( | |
self.request.dbsession, | |
self.context.entity.id, | |
max_depth = depth | |
).as_tree() | |
self.request.response.content_type = 'application/json' | |
self.request.response.headers['Access-Control-Allow-Origin'] = '*' | |
self.request.response.text = json.dumps(result, cls=Encoder) | |
return self.request.response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment