Created
February 25, 2021 13:21
-
-
Save silenius/c6fc64c45d496207411993779f1020c1 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', 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