Skip to content

Instantly share code, notes, and snippets.

@silenius
Created February 25, 2021 13:21
Show Gist options
  • Save silenius/c6fc64c45d496207411993779f1020c1 to your computer and use it in GitHub Desktop.
Save silenius/c6fc64c45d496207411993779f1020c1 to your computer and use it in GitHub Desktop.
@view_config(request_method='GET', renderer='json',
name='hierarchy', accept='application/json')
def hierarchy(self):
schema = FolderSchema(only=('id', 'title'))
class Encoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, Folder):
return schema.dump(obj)
return super().default(obj)
result = get_children(
self.request.dbsession,
self.context.entity.id
)
self.request.response.content_type = 'application/json'
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