Node publisher¶
A node publisher translates between paths and URLs and publishes views for a given path. Typical usage:
from nodular import NodeRegistry, NodePublisher
from myapp import app, root, registry
assert isinstance(registry, NodeRegistry)
# Publish everything under /
publisher = NodePublisher(root, registry, '/')
@app.route('/<path:anypath>', methods=['GET', 'POST', 'PUT', 'DELETE'])
def publish_path(anypath):
return publisher.publish(anypath)
-
class
nodular.publisher.
NodePublisher
(root, registry, basepath, urlpath=None)¶ NodePublisher publishes node paths.
Parameters: - root – Root node for lookups (Node instance or integer primary key id).
- registry (
NodeRegistry
) – Registry for looking up views. - basepath (string) – Base path to publish from, typically
'/'
. - urlpath (string) – URL path to publish to, typically also
'/'
. Defaults to thebasepath
value.
NodePublisher may be instantiated either globally or per request, but requires a root node to query against. Depending on your setup, this may be available only at request time.
-
publish
(path, user=None, permissions=None)¶ Publish a path using views from the registry.
Parameters: - path – Path to be published (relative to the initialized basepath).
- user – User we are rendering for (required for permission checks).
- permissions – Externally-granted permissions for this user.
Returns: Result of the called view or
NotFound
exception if no view is found.publish()
usestraverse()
to find a node to publish.
-
traverse
(path, redirect=True)¶ Traverse to the node at the given path, returning the closest matching node and status.
Parameters: - path – Path to be traversed.
- redirect – If True (default), look for redirects when there’s a partial match.
Returns: Tuple of (status, node, path)
Return value
status
is one ofMATCH
,REDIRECT
,PARTIAL
,NOROOT
orGONE
. For an exactMATCH
,node
is the found node andpath
isNone
. For aREDIRECT
orPARTIAL
match,node
is the closest matching node andpath
is the URL path to redirect to OR the remaining unmatched path.NOROOT
implies the root node is missing. If redirects are enabled and aNodeAlias
is found indicating a node is deleted, status isGONE
.traverse()
does not require a registry since it does not look up views.NodePublisher
may be initialized withregistry=None
if only used for traversal.
-
url_for
(node, action=u'view', _external=False, **kwargs)¶ Generates a URL to the given node with the view.
Parameters: - node – Node instance
- endpoint – the endpoint of the URL (name of the function)
-
class
nodular.publisher.
TRAVERSE_STATUS
¶ Traversal status codes.