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.

  • 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 the basepath 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.

  • 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.

Result of the called view or NotFound exception if no view is found.

publish() uses traverse() 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.

  • path – Path to be traversed.
  • redirect – If True (default), look for redirects when there’s a partial match.

Tuple of (status, node, path)

Return value status is one of MATCH, REDIRECT, PARTIAL, NOROOT or GONE. For an exact MATCH, node is the found node and path is None. For a REDIRECT or PARTIAL match, node is the closest matching node and path is the URL path to redirect to OR the remaining unmatched path. NOROOT implies the root node is missing. If redirects are enabled and a NodeAlias is found indicating a node is deleted, status is GONE.

traverse() does not require a registry since it does not look up views. NodePublisher may be initialized with registry=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.

  • node – Node instance
  • endpoint – the endpoint of the URL (name of the function)
class nodular.publisher.TRAVERSE_STATUS

Traversal status codes.