Skip to content

Instantly share code, notes, and snippets.

@silenius
Created May 11, 2021 09:02
Show Gist options
  • Save silenius/b412d278eb10274cbf09991992c8b938 to your computer and use it in GitHub Desktop.
Save silenius/b412d278eb10274cbf09991992c8b938 to your computer and use it in GitHub Desktop.
@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