core.prototypes.tree
¶
Module Contents¶
Classes¶
Tree is a ViUR BasicApplication. |
Attributes¶
- core.prototypes.tree.SkelType¶
- class core.prototypes.tree.TreeSkel¶
Bases:
viur.core.skeleton.Skeleton
- parententry¶
- parentrepo¶
- sortindex¶
- classmethod refresh(skelValues)¶
- class core.prototypes.tree.Tree(moduleName, modulePath, *args, **kwargs)¶
Bases:
viur.core.prototypes.BasicApplication
Tree is a ViUR BasicApplication.
In this application, entries are hold in directories, which can be nested. Data in a Tree application always consists of nodes (=directories) and leafs (=files).
- Variables:
kindName (str) – Name of the kind of data entities that are managed by the application. This information is used to bind a specific
viur.core.skeleton.Skeleton
-class to the application. For more information, refer to the function_resolveSkel()
. In difference to the other ViUR BasicApplication, the kindName in Trees evolve into the kindNames kindName + “node” and kindName + “leaf”, because information can be stored in different kinds.adminInfo (dict | callable) – todo short info on how to use adminInfo.
- accessRights = ['add', 'edit', 'view', 'delete']¶
- nodeSkelCls¶
- leafSkelCls¶
- adminInfo()¶
- _checkSkelType(skelType: Any) SkelType | None ¶
Checks for correct skelType.
Either returns the type provided, or None in case it is invalid.
- _resolveSkelCls(skelType: SkelType, *args, **kwargs) Type[viur.core.skeleton.Skeleton] ¶
- baseSkel(skelType: SkelType, *args, **kwargs) viur.core.skeleton.SkeletonInstance ¶
Return unmodified base skeleton for the given skelType.
See also
- viewSkel(skelType: SkelType, *args, **kwargs) viur.core.skeleton.SkeletonInstance ¶
Retrieve a new instance of a
viur.core.skeleton.Skeleton
that is used by the application for viewing an existing entry from the list.The default is a Skeleton instance returned by
baseSkel()
.See also
- Returns:
Returns a Skeleton instance for viewing an entry.
- addSkel(skelType: SkelType, *args, **kwargs) viur.core.skeleton.SkeletonInstance ¶
Retrieve a new instance of a
viur.core.skeleton.Skeleton
that is used by the application for adding an entry to the list.The default is a Skeleton instance returned by
baseSkel()
.See also
- Returns:
Returns a Skeleton instance for adding an entry.
- editSkel(skelType: SkelType, *args, **kwargs) viur.core.skeleton.SkeletonInstance ¶
Retrieve a new instance of a
viur.core.skeleton.Skeleton
that is used by the application for editing an existing entry from the list.The default is a Skeleton instance returned by
baseSkel()
.See also
- Returns:
Returns a Skeleton instance for editing an entry.
- ensureOwnModuleRootNode() viur.core.db.Entity ¶
Ensures, that general root-node for the current module exists. If no root-node exists yet, it will be created.
- Returns:
The entity of the root-node.
- getAvailableRootNodes(*args, **kwargs) List[Dict[Literal[name, key], str]] ¶
Default function for providing a list of root node items. This list is requested by several module-internal functions and must be overridden by a custom functionality. The default stub for this function returns an empty list. An example implementation could be the following: .. code-block:: python
- Parameters:
args – Can be used in custom implementations.
kwargs – Can be used in custom implementations.
- Returns:
Returns a list of dicts which must provide a “key” and a “name” entry with respective information.
- getRootNode(entryKey: str) viur.core.skeleton.SkeletonInstance ¶
Returns the root-node for a given child.
- Parameters:
entryKey – URL-Safe key of the child entry
- Returns:
The entity of the root-node.
- updateParentRepo(parentNode: str, newRepoKey: str, depth: int = 0)¶
Recursively fixes the parentrepo key after a move operation.
This will delete all entries which are children of nodeKey, except key nodeKey.
- Parameters:
parentNode – URL-safe key of the node which children should be fixed.
newRepoKey – URL-safe key of the new repository.
depth – Safety level depth preventing infinitive loops.
- pathToKey(key: viur.core.db.Key)¶
Returns the recursively expanded path through the Tree from the root-node to a requested node. :param key: Key of the destination node. :returns: An nested dictionary with information about all nodes in the path from root to the requested node.
- listRootNodes(*args, **kwargs) Any ¶
Renders a list of all available repositories for the current user using the modules default renderer.
- Returns:
The rendered representation of the available root-nodes.
- list(skelType: SkelType, *args, **kwargs) Any ¶
Prepares and renders a list of entries.
All supplied parameters are interpreted as filters for the elements displayed.
Unlike other ViUR BasicApplications, the access control in this function is performed by calling the function
listFilter()
, which updates the query-filter to match only elements which the user is allowed to see.See also
listFilter()
,viur.core.db.mergeExternalFilter()
- Returns:
The rendered list objects for the matching entries.
- Raises:
viur.core.errors.Unauthorized
, if the current user does not have the required permissions.
- structure(skelType: SkelType, *args, **kwargs) Any ¶
- Returns:
Returns the structure of our skeleton as used in list/view. Values are the defaultValues set in each bone.
- Raises:
viur.core.errors.NotAcceptable
, when an incorrect skelType is provided.- Raises:
viur.core.errors.Unauthorized
, if the current user does not have the required permissions.
- view(skelType: SkelType, key: str, *args, **kwargs) Any ¶
Prepares and renders a single entry for viewing.
The entry is fetched by its key and its skelType. The function performs several access control checks on the requested entity before it is rendered.
- Returns:
The rendered representation of the requested entity.
- Parameters:
skelType – May either be “node” or “leaf”.
key – URL-safe key of the parent.
- Raises:
viur.core.errors.NotAcceptable
, when an incorrect skelType is provided.- Raises:
viur.core.errors.NotFound
, when no entry with the given key was found.- Raises:
viur.core.errors.Unauthorized
, if the current user does not have the required permissions.
- add(skelType: SkelType, node: str, *args, **kwargs) Any ¶
Add a new entry with the given parent node, and render the entry, eventually with error notes on incorrect data. Data is taken by any other arguments in kwargs.
The function performs several access control checks on the requested entity before it is added.
- Parameters:
skelType – Defines the type of the new entry and may either be “node” or “leaf”.
node – URL-safe key of the parent.
- Returns:
The rendered, added object of the entry, eventually with error hints.
- Raises:
viur.core.errors.NotAcceptable
, when no valid skelType was provided.- Raises:
viur.core.errors.NotFound
, when no valid node was found.- Raises:
viur.core.errors.Unauthorized
, if the current user does not have the required permissions.- Raises:
viur.core.errors.PreconditionFailed
, if the skey could not be verified.
- edit(skelType: SkelType, key: str, *args, **kwargs) Any ¶
Modify an existing entry, and render the entry, eventually with error notes on incorrect data. Data is taken by any other arguments in kwargs.
The function performs several access control checks on the requested entity before it is added.
See also
- Parameters:
skelType – Defines the type of the entry that should be modified and may either be “node” or “leaf”.
key – URL-safe key of the item to be edited.
- Returns:
The rendered, modified object of the entry, eventually with error hints.
- Raises:
viur.core.errors.NotAcceptable
, when no valid skelType was provided.- Raises:
viur.core.errors.NotFound
, when no valid node was found.- Raises:
viur.core.errors.Unauthorized
, if the current user does not have the required permissions.- Raises:
viur.core.errors.PreconditionFailed
, if the skey could not be verified.
- delete(skelType: SkelType, key: str, *args, **kwargs) Any ¶
Deletes an entry or an directory (including its contents).
The function runs several access control checks on the data before it is deleted.
See also
- Parameters:
skelType – Defines the type of the entry that should be deleted and may either be “node” or “leaf”.
key – URL-safe key of the item to be deleted.
- Returns:
The rendered, deleted object of the entry.
- Raises:
viur.core.errors.NotFound
, when no entry with the given key was found.- Raises:
viur.core.errors.Unauthorized
, if the current user does not have the required permissions.- Raises:
viur.core.errors.PreconditionFailed
, if the skey could not be verified.
- deleteRecursive(parentKey: str)¶
Recursively processes a delete request.
This will delete all entries which are children of nodeKey, except key nodeKey.
- Parameters:
parentKey – URL-safe key of the node which children should be deleted.
- move(skelType: SkelType, key: str, parentNode: str, *args, **kwargs) str ¶
Move a node (including its contents) or a leaf to another node.
See also
- Parameters:
skelType – Defines the type of the entry that should be moved and may either be “node” or “leaf”.
key – URL-safe key of the item to be moved.
parentNode – URL-safe key of the destination node, which must be a node.
- Returns:
The rendered, edited object of the entry.
- Raises:
viur.core.errors.NotFound
, when no entry with the given key was found.- Raises:
viur.core.errors.Unauthorized
, if the current user does not have the required permissions.- Raises:
viur.core.errors.PreconditionFailed
, if the skey could not be verified.
- listFilter(query: viur.core.db.Query) viur.core.db.Query | None ¶
Access control function on item listing.
This function is invoked by the
list()
renderer and the related Jinja2 fetching function, and is used to modify the provided filter parameter to match only items that the current user is allowed to see.- Parameters:
query – Query which should be altered.
- Returns:
The altered filter, or None if access is not granted.
- canView(skelType: SkelType, skel: viur.core.skeleton.SkeletonInstance) bool ¶
Checks if the current user can view the given entry. Should be identical to what’s allowed by listFilter. By default, meth:listFilter is used to determine what’s allowed and whats not; but this method can be overridden for performance improvements (to eliminate that additional database access). :param skel: The entry we check for :return: True if the current session is authorized to view that entry, False otherwise
- canAdd(skelType: SkelType, parentNodeSkel: viur.core.skeleton.SkeletonInstance | None) bool ¶
Access control function for adding permission.
Checks if the current user has the permission to add a new entry.
The default behavior is: - If no user is logged in, adding is generally refused. - If the user has “root” access, adding is generally allowed. - If the user has the modules “add” permission (module-add) enabled, adding is allowed.
It should be overridden for a module-specific behavior.
See also
- Parameters:
skelType – Defines the type of the node that should be added.
parentNodeSkel – The parent node where a new entry should be added.
- Returns:
True, if adding entries is allowed, False otherwise.
- canEdit(skelType: SkelType, skel: viur.core.skeleton.SkeletonInstance) bool ¶
Access control function for modification permission.
Checks if the current user has the permission to edit an entry.
The default behavior is: - If no user is logged in, editing is generally refused. - If the user has “root” access, editing is generally allowed. - If the user has the modules “edit” permission (module-edit) enabled, editing is allowed.
It should be overridden for a module-specific behavior.
See also
- Parameters:
skelType – Defines the type of the node that should be edited.
skel – The Skeleton that should be edited.
- Returns:
True, if editing entries is allowed, False otherwise.
- canDelete(skelType: SkelType, skel: viur.core.skeleton.SkeletonInstance) bool ¶
Access control function for delete permission.
Checks if the current user has the permission to delete an entry.
The default behavior is: - If no user is logged in, deleting is generally refused. - If the user has “root” access, deleting is generally allowed. - If the user has the modules “deleting” permission (module-delete) enabled, deleting is allowed.
It should be overridden for a module-specific behavior.
- Parameters:
skelType – Defines the type of the node that should be deleted.
skel – The Skeleton that should be deleted.
See also
- Returns:
True, if deleting entries is allowed, False otherwise.
- canMove(skelType: SkelType, node: viur.core.skeleton.SkeletonInstance, destNode: viur.core.skeleton.SkeletonInstance) bool ¶
Access control function for moving permission.
Checks if the current user has the permission to move an entry.
The default behavior is: - If no user is logged in, deleting is generally refused. - If the user has “root” access, deleting is generally allowed. - If the user has the modules “edit” permission (module-edit) enabled, moving is allowed.
It should be overridden for a module-specific behavior.
- Parameters:
skelType – Defines the type of the node that shall be deleted.
node – URL-safe key of the node to be moved.
destNode – URL-safe key of the node where node should be moved to.
See also
- Returns:
True, if deleting entries is allowed, False otherwise.
- onAdd(skelType: SkelType, skel: viur.core.skeleton.SkeletonInstance)¶
Hook function that is called before adding an entry.
It can be overridden for a module-specific behavior.
- Parameters:
skelType – Defines the type of the node that shall be added.
skel – The Skeleton that is going to be added.
- onAdded(skelType: SkelType, skel: viur.core.skeleton.SkeletonInstance)¶
Hook function that is called after adding an entry.
It should be overridden for a module-specific behavior. The default is writing a log entry.
- Parameters:
skelType – Defines the type of the node that has been added.
skel – The Skeleton that has been added.
- onEdit(skelType: SkelType, skel: viur.core.skeleton.SkeletonInstance)¶
Hook function that is called before editing an entry.
It can be overridden for a module-specific behavior.
- Parameters:
skelType – Defines the type of the node that shall be edited.
skel – The Skeleton that is going to be edited.
See also
- onEdited(skelType: SkelType, skel: viur.core.skeleton.SkeletonInstance)¶
Hook function that is called after modifying an entry.
It should be overridden for a module-specific behavior. The default is writing a log entry.
- Parameters:
skelType – Defines the type of the node that has been edited.
skel – The Skeleton that has been modified.
- onView(skelType: SkelType, skel: viur.core.skeleton.SkeletonInstance)¶
Hook function that is called when viewing an entry.
It should be overridden for a module-specific behavior. The default is doing nothing.
- Parameters:
skelType – Defines the type of the node that is viewed.
skel – The Skeleton that is viewed.
See also
- onDelete(skelType: SkelType, skel: viur.core.skeleton.SkeletonInstance)¶
Hook function that is called before deleting an entry.
It can be overridden for a module-specific behavior.
- Parameters:
skelType – Defines the type of the node that shall be deleted.
skel – The Skeleton that is going to be deleted.
See also
- onDeleted(skelType: SkelType, skel: viur.core.skeleton.SkeletonInstance)¶
Hook function that is called after deleting an entry.
It should be overridden for a module-specific behavior. The default is writing a log entry.
..warning: Saving the skeleton again will undo the deletion (if the skeleton was a leaf or a node with no children).
- Parameters:
skelType – Defines the type of the node that is deleted.
skel – The Skeleton that has been deleted.
See also