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 auser
ortoken
is provided instead,roles_for()
is called:# This typical call: obj.access_for(user=current_user) # Is shorthand for: obj.access_for(roles=obj.roles_for(user=current_user))
-
aliases
¶ Dictionary of all aliases for renamed, moved or deleted sub-nodes.
-
as_dict
()¶ Export the node as a dictionary.
-
buid
¶ URL-friendly UUID representation, using URL-safe Base64 (BUID)
-
etype
¶ 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.
-
id
¶ Database identity for this model, used for foreign key references from other models
-
import_from
(data)¶ Import the node from a dictionary.
-
make_name
(reserved=[])¶ Autogenerates a
name
from thetitle
. 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.
-
name
¶ The URL name of this object, unique within a parent container
-
nodes
¶ Dictionary of all sub-nodes.
-
parent_id
¶ Container for this node (used mainly to enforce uniqueness of ‘name’).
-
path
¶ Path to this node for URL traversal.
-
permissions
(user, inherited=None)¶ Permissions for this model, plus permissions inherited from the parent.
-
query_class
¶ alias of
Query
-
roles_for
(user=None, token=None)¶ Return roles available to the given
user
ortoken
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 eitheruser
ortoken
is specified, the roleuser
is granted. If neither,anon
is granted.
-
root
¶ The root node for this node’s tree.
-
short_title
()¶ Generates an abbreviated title by subtracting the parent’s title from this instance’s title.
-
suuid
¶ URL-friendly UUID representation, using ShortUUID
-
title
¶ 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_id
¶ URL-friendly UUID representation as a hex string
-
users_with
(roles)¶ 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.
-
-
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.
-
query_class
¶ 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 nodetype
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
andNode.aliases
.Parameters: - 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.
Note
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.