Traversal¶
Introduction¶
Websauna supports traversal pattern to map out resource trees to URLs. It is extensively used by the default CRUD and admin interfaces.
Websauna traversal is based on Pyramid traversal architecture.
Resources¶
An object representing a node in the resource tree of an application. If traversal is used, a resource is an element in the resource tree traversed by the system. When traversal is used, a resource becomes the context of a view.
Websauna provides websauna.system.core.traversal.Resource
base class from which you can inherit all resource classes. The API documentation explains how to set up resource objects.
Resource publicity¶
The default Websauna Root object declares all traverable content to be public. If you need to make your resources private see Making travesable hierarchies protected.
Breadcrumbs¶
It’s very easy to generate breadcrumbs (path bar) from traversal hierarchy. See websauna.system.core.breadcrumbs
for more information.
Examples¶
See websauna.blog.views module for example how to set up a traversal for your frontend pages.
Site root object¶
Websauna provides a websauna.system.core.root.Root
class that is the default root object for traversal. This object defines user and group permissions on the site level.
You can override this object in websauna.system.Initializer.configure_root()
.
Example root.py
:
from pyramid.security import Allow
from websauna.system.core import root as base
class Root(base.Root):
"""Redefine site root permissions."""
# Additional site specific permissions given to the admin group
__acl__ = [
(Allow, "group:admin", "manage-content")
]
# Default websauna permissions
__acl__ += base.Root.__acl__
Example __init__.py
:
class Initializer(websauna.system.Initializer):
def configure_root(self):
from myapp.root import Root
self.config.set_root_factory(Root.root_factory)