Node model

Nodular’s NodeMixin and Node models are the base classes for all content objects.

class nodular.node.Node(**kwargs)

Base class for all content objects.

access_for(roles=None, user=None, token=None)

Return a proxy object that limits read and write access to attributes based on the user’s roles. If the roles parameter isn’t provided, but a user or token is provided instead, roles_for() is called:

# This typical call:
# Is shorthand for:

Dictionary of all aliases for renamed, moved or deleted sub-nodes.


Export the node as a dictionary.


URL-friendly UUID representation, using URL-safe Base64 (BUID)


Effective type of this instance

classmethod get(buid)

Get a node by its buid.

getprop(key, default=None)

Return the inherited value of a property from the closest parent node on which it was set.


Database identity for this model, used for foreign key references from other models


Import the node from a dictionary.


Autogenerates a name from the title. If the auto-generated name is already in use in this model, make_name() tries again by suffixing numbers starting with 2 until an available name is found.

make_token_for(user, roles=None, token=None)

Generate a token for the specified user that grants access to this object alone, with either all roles available to the user, or just the specified subset. If an existing token is available, add to it.

This method should return None if a token cannot be generated. Must be implemented by subclasses.


The URL name of this object, unique within a parent container


Dictionary of all sub-nodes.


Container for this node (used mainly to enforce uniqueness of ‘name’).


Path to this node for URL traversal.

permissions(user, inherited=None)

Permissions for this model, plus permissions inherited from the parent.


alias of Query

roles_for(user=None, token=None)

Return roles available to the given user or token on this object. The data type for both parameters are intentionally undefined here. Subclasses are free to define them in any way appropriate. Users and tokens are assumed to be valid.

The role all is always granted. If either user or token is specified, the role user is granted. If neither, anon is granted.


The root node for this node’s tree.


Generates an abbreviated title by subtracting the parent’s title from this instance’s title.


URL-friendly UUID representation, using ShortUUID


The title of this object

upsert(parent, name, **fields)

Insert or update an instance

url_for(action='view', **kwargs)

Return public URL to this instance for a given action (default ‘view’)


URL-friendly UUID representation as a hex string


Return an iterable of all users who have the specified roles on this object. The iterable may be a list, tuple, set or SQLAlchemy query.

Must be implemented by subclasses.


UUID column, or synonym to existing id column if that is a UUID

class nodular.node.NodeAlias(**kwargs)

When a node is renamed, it gets an alias connecting the old name to the new. NodeAlias makes it possible for users to rename nodes without breaking links.


alias of Query

class nodular.node.NodeMixin

NodeMixin provides functionality for content objects to connect to the Node base table. NodeMixin and Node should be used together:

class MyContentType(NodeMixin, Node):
    __tablename__ = 'my_content_type'
    my_column = Column(...)

NodeMixin will use __tablename__ as the node type identifier and will autogenerate a __title__ attribute. This title is used in the UI when the user adds a new node.

permissions(user, inherited=None)

Return permissions available to the given user on this object

class nodular.node.ProxyDict(parent, collection_name, childclass, keyname, parentkey)

Proxies a dictionary on a relationship. This is intended for use with lazy='dynamic' relationships, but can also be used with regular InstrumentedList relationships.

ProxyDict is used for Node.nodes and Node.aliases.

  • parent – The instance in which this dictionary exists.
  • collection_name – The relationship that is being proxied.
  • childclass – The model referred to in the relationship.
  • keyname – Attribute in childclass that will be the dictionary key.
  • parentkey – Attribute in childclass that refers back to this parent.
clear() → None. Remove all items from D.
items() → list of D's (key, value) pairs, as 2-tuples
iteritems() → an iterator over the (key, value) items of D
iterkeys() → an iterator over the keys of D
itervalues() → an iterator over the values of D
pop(k[, d]) → v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() → (k, v), remove and return some (key, value) pair

as a 2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D
update([E, ]**F) → None. Update D from mapping/iterable E and F.

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values() → list of D's values
nodular.node.pathjoin(a, *p)

Join two or more pathname components, inserting ‘/’ as needed. If any component is an absolute path, all previous path components will be discarded.


This function is the same as os.path.join() on POSIX systems but is reproduced here so that Nodular can be used in non-POSIX environments.