Skip to content

Instantly share code, notes, and snippets.

@silenius
Last active February 25, 2021 12:01
Show Gist options
  • Save silenius/a0ef358227a655b187b1708b8fc7cdb4 to your computer and use it in GitHub Desktop.
Save silenius/a0ef358227a655b187b1708b8fc7cdb4 to your computer and use it in GitHub Desktop.
@view_config(request_method='GET', renderer='string',
name='hierarchy', accept='application/json')
def hierarchy(self):
from amnesia.modules.folder import Folder
from amnesia.modules.folder.services import get_children
from amnesia.modules.folder.validation import FolderSchema
from pyramid.renderers import JSON
from pyramid.response import Response
schema = FolderSchema(only=('id', 'title'))
json = JSON()
json.add_adapter(Folder, lambda obj, req: schema.dump(obj))
result = get_children(
self.request.dbsession,
self.context.entity.id
)
return json(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment