prototypes

Basic

class server.prototypes.basic.BasicApplication(moduleName, modulePath, *args, **kwargs)

BasicApplication is a generic class serving as the base for the four BasicApplications.

Variables:kindName (str) – Name of the kind of data entities that are managed by the application. This information is used to bind a specific server.skeleton.Skeleton-class to the application. For more information, refer to the function _resolveSkel().

Hierarchy

class server.prototypes.hierarchy.Hierarchy(moduleName, modulePath, *args, **kwargs)

Hierarchy is a ViUR BasicApplication.

It is used for multiple data entities of the same kind, which are stored in an hierarchical order. Every element of the hierarchy can be a child of another element or may contain more children. It needs to be sub-classed for individual modules.

Variables:
  • kindName (str) – Name of the kind of data entities that are managed by the application. This information is used to bind a specific server.skeleton.Skeleton-class to the application. For more information, refer to the function _resolveSkel().
  • adminInfo (dict | callable) – todo short info on how to use adminInfo.
add(parent, *args, **kwargs)

Add a new entry with the given parent, 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

addSkel(), onItemAdded(), canAdd()

Parameters:parent (str) – URL-safe key of the parent.
Returns:The rendered, added object of the entry, eventually with error hints.
Raises:server.errors.NotAcceptable, when no valid parent was found.
Raises:server.errors.Unauthorized, if the current user does not have the required permissions.
Raises:server.errors.PreconditionFailed, if the skey could not be verified.
addSkel(*args, **kwargs)

Retrieve a new instance of a server.skeleton.Skeleton that is used by the application for adding an entry to the hierarchy.

The default is a Skeleton instance returned by _resolveSkel().

See also

viewSkel(), editSkel(), _resolveSkel()

Returns:Returns a Skeleton instance for adding an entry.
Return type:server.skeleton.Skeleton
canAdd(parent)

Access control function for adding permission.

Checks if the current user has the permission to add a new entry to parent.

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

add()

Parameters:parent (str) – URL-safe key of the parent node under which the element shall be added.
Returns:True, if adding entries is allowed, False otherwise.
Return type:bool
canDelete(skel)

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:skel (server.skeleton.Skeleton) – The Skeleton that should be deleted.

See also

delete()

Returns:True, if deleting entries is allowed, False otherwise.
Return type:bool
canEdit(skel)

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

edit()

Parameters:skel (server.skeleton.Skeleton) – The Skeleton that should be edited.
Returns:True, if editing entries is allowed, False otherwise.
Return type:bool
canList(parent)

Access control function for listing permission.

Checks if the current user has the permission to list the children of the given parent.

The default behavior is: - If no user is logged in, listing is generally refused. - If the user has “root” access, listing is generally allowed. - If the user has the modules “view” permission (module-view) enabled, listing is allowed.

It should be overridden for a module-specific behavior.

See also

list()

Parameters:parent (str) – URL-safe key of the parent.
Returns:True, if listing is allowed, False otherwise.
Return type:bool
canPreview()

Access control function for preview permission.

Checks if the current user has the permission to preview an entry.

The default behavior is: - If no user is logged in, previewing is generally refused. - If the user has “root” access, previewing is generally allowed. - If the user has the modules “add” or “edit” permission (module-add, module-edit) enabled, previewing is allowed.

It should be overridden for module-specific behavior.

See also

preview()

Returns:True, if previewing entries is allowed, False otherwise.
Return type:bool
canReparent(item, dest)

Access control function for item moving permission.

Checks if the current user has the permission to move item to dest.

The default behavior is: - If no user is logged in, any modification is generally refused. - If the user has “root” access, modification 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:
  • item (float) – URL-safe key of the entry.
  • item – URL-safe key of the new parent to be moved to.

See also

reparent()

Returns:True, if changing the order of entries is allowed, False otherwise.
Return type:bool
canSetIndex(item, index)

Access control function for changing order permission.

Checks if the current user has the permission to change the ordering of an entry.

The default behavior is: - If no user is logged in, any modification is generally refused. - If the user has “root” access, modification is generally allowed. - If the user has the modules “edit” or “add” permission (module-edit, module-add) enabled, modification is allowed.

It should be overridden for a module-specific behavior.

Parameters:
  • item (float) – URL-safe key of the entry.
  • item – New sortindex for this item.

See also

setIndex()

Returns:True, if changing the order of entries is allowed, False otherwise.
Return type:bool
canView(skel)

Access control function for viewing permission.

Checks if the current user has the permission to view an entry.

The default behavior is: - If no user is logged in, viewing is generally refused. - If the user has “root” access, viewing is generally allowed. - If the user has the modules “view” permission (module-view) enabled, viewing is allowed.

It should be overridden for a module-specific behavior.

See also

view()

Parameters:skel (server.skeleton.Skeleton) – The Skeleton that should be viewed.
Returns:True, if viewing is allowed, False otherwise.
Return type:bool
clone(fromRepo, toRepo, fromParent=None, toParent=None, *args, **kwargs)

Clones a hierarchy recursively.

This function only initiates the cloning process, which is performed in the background. It states only a successful result when the clone action has been correctly initiated.

Parameters:
  • fromRepo (str) – URL-safe key of the key to the repository (=root-node Key) to clone from.
  • toRepo (str) – URL-safe key of the key to the repository (=root-node Key) to clone to.
  • fromParent (str) – URL-safe key of the parent to clone from; for root nodes, this is equal to fromRepo, and can be omitted.
  • toParent (str) – URL-safe key of the parent to clone to; for root nodes, this is equal to toRepo, and can be omitted.
Returns:

A rendered success result generated by the default renderer.

Raises:

server.errors.NotAcceptable, when no valid parent was found.

Raises:

server.errors.Unauthorized, if the current user does not have the required permissions.

Raises:

server.errors.PreconditionFailed, if the skey could not be verified.

delete(key, skey, *args, **kwargs)

Delete an entry and all its children.

The function runs several access control checks on the data before it is deleted.

See also

canDelete(), editSkel(), onItemDeleted()

Parameters:key (str) – URL-safe key of the entry to be deleted.
Returns:The rendered, deleted object of the entry.
Raises:server.errors.NotFound, when no entry with the given key was found.
Raises:server.errors.Unauthorized, if the current user does not have the required permissions.
Raises:server.errors.PreconditionFailed, if the skey could not be verified.
deleteRecursive(key)

Recursively processes a delete request.

This will delete all entries which are children of key, except key itself.

Parameters:key (str) – URL-safe key of the node which children should be deleted.
Returns:The number of deleted objects.
Return type:int
edit(*args, **kwargs)

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 entry is fetched by its entity key, which either is provided via kwargs[“key”], or as the first parameter in args. The function performs several access control checks on the requested entity before it is modified.

See also

editSkel(), onItemEdited(), canEdit()

Returns:The rendered, edited object of the entry, eventually with error hints.
Raises:server.errors.NotAcceptable, when no key is provided.
Raises:server.errors.NotFound, when no entry with the given key was found.
Raises:server.errors.Unauthorized, if the current user does not have the required permissions.
Raises:server.errors.PreconditionFailed, if the skey could not be verified.
editSkel(*args, **kwargs)

Retrieve a new instance of a server.skeleton.Skeleton that is used by the application for editing an existing entry from the hierarchy.

The default is a Skeleton instance returned by _resolveSkel().

See also

viewSkel(), editSkel(), _resolveSkel()

Returns:Returns a Skeleton instance for editing an entry.
Return type:server.skeleton.Skeleton
ensureOwnModuleRootNode()

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.
Return type:server.db.Entity
ensureOwnUserRootNode()

Ensures, that an root-node for the current user exists. If no root-node exists yet, it will be created.

Returns:The entity of the root-node or None, if this was request was made by a guest.
Return type:server.db.Entity
getRootNode(entryKey)

Returns the root-node for a given child.

Parameters:entryKey (str) – URL-Safe key of the child entry
Returns:The entity of the root-node.
Return type:server.db.Entity
isOwnUserRootNode(repo)

Checks, if the given rootNode is owned by the current user.

Parameters:repo (str) – URL-safe key of the root-node.
Returns:True if the user owns this root-node, False otherwise.
Return type:bool
isValidParent(parent)

Checks wherever a given parent is valid.

Parameters:parent (str) – Parent to test
Returns:Test result.
Return type:bool
jinjaEnv(env)

Provides some additional Jinja2 template functions for hierarchy applications.

These function are:

  • pathToKey() alias getPathToKey()
  • canAdd()
  • canPreview()
  • canEdit()
  • canView()
  • canDelete()
  • canSetIndex()
  • canList()
  • canReparent()

..warning:: It is important to call the super-class-function of Hierarchy when this function is overridden from a sub-classed module.

list(parent, *args, **kwargs)

List the entries which are direct children of the given parent. Any other supplied parameters are interpreted as filters for the elements displayed.

See also

canList(), server.db.mergeExternalFilter()

Parameters:parent (str) – URL-safe key of the parent.
Returns:The rendered list objects for the matching entries.
Raises:server.errors.Unauthorized, if the current user does not have the required permissions.
Raises:server.errors.NotFound, if parent could not be found.
listRootNodes(*args, **kwargs)

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.
Return type:str
onItemAdded(skel)

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:skel (server.skeleton.Skeleton) – The Skeleton that has been added.

See also

add()

onItemChanged(skel)

Hook function that is called after changing an entry.

It should be overridden for a module-specific behavior. The default is doing nothing because it is additional to the other on* functions.

Parameters:skel (server.skeleton.Skeleton) – The Skeleton that has been deleted.
onItemCloned(skel)

Hook function that is called after cloning an entry.

It should be overridden for a module-specific behavior. The default is writing a log entry.

Parameters:skel (server.skeleton.Skeleton) – The Skeleton that has been cloned.

See also

_clone()

onItemDeleted(skel)

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.

Parameters:skel (server.skeleton.Skeleton) – The Skeleton that has been deleted.

See also

delete()

onItemEdited(skel)

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:skel (server.skeleton.Skeleton) – The Skeleton that has been modified.

See also

edit()

onItemReparent(skel)

Hook function that is called after reparenting an entry.

It should be overridden for a module-specific behavior. The default is writing a log entry.

Parameters:skel (server.skeleton.Skeleton) – The Skeleton that has been reparented.

See also

reparent()

onItemSetIndex(skel)

Hook function that is called after setting a new index an entry.

It should be overridden for a module-specific behavior. The default is writing a log entry.

Parameters:skel (server.skeleton.Skeleton) – The Skeleton that has got a new index.

See also

setIndex()

onItemViewed(skel)

Hook function that is called when viewing an entry.

It should be overridden for a module-specific behavior. The default is doing nothing.

Parameters:skel (server.skeleton.Skeleton) – The Skeleton that is viewed.

See also

view()

pathToKey(key=None)

Returns the recursively expanded path through the Hierarchy from the root-node to a requested node.

Parameters:key (str) – URL-safe key of the destination entity.
Returns:An nested dictionary with information about all nodes in the path from root to the requested node.
Return type:dict
preview(skey, *args, **kwargs)

Renders data for an entry, without reading from the database. This function allows to preview an entry without writing it to the database.

Any entity values are provided via kwargs.

The function uses the viewTemplate of the application.

Returns:The rendered representation of the the supplied data.
reparent(item, dest, skey, *args, **kwargs)

Moves an entry item (and everything beneath it) to another parent-node dest.

See also

canReparent()

Parameters:
  • item (str) – URL-safe key of the item which will be moved.
  • dest (str) – URL-safe key of the new parent for this item.
Returns:

A rendered success result generated by the default renderer.

Raises:

server.errors.NotFound, when no entry with the given id was found.

Raises:

server.errors.Unauthorized, if the current user does not have the required permissions.

Raises:

server.errors.PreconditionFailed, if the skey could not be verified.

setIndex(item, index, skey, *args, **kwargs)

Changes the order of the elements in the current level by changing the index of item.

See also

canSetIndex()

Parameters:
  • item (str) – URL-safe key of the item which index should be changed.
  • index (str) – New index for this item. This value must be cast-able to float.
Returns:

A rendered success result generated by the default renderer.

Raises:

server.errors.NotFound, when no entry with the given key was found.

Raises:

server.errors.Unauthorized, if the current user does not have the required permissions.

Raises:

server.errors.PreconditionFailed, if the skey could not be verified.

view(*args, **kwargs)

Prepares and renders a single entry for viewing.

The entry is fetched by its entity key, which either is provided via kwargs[“key”], or as the first parameter in args. The function performs several access control checks on the requested entity before it is rendered.

See also

viewSkel(), canView(), onItemViewed()

Returns:The rendered representation of the requested entity.
Raises:server.errors.NotAcceptable, when no key is provided.
Raises:server.errors.NotFound, when no entry with the given key was found.
Raises:server.errors.Unauthorized, if the current user does not have the required permissions.
viewSkel(*args, **kwargs)

Retrieve a new instance of a server.skeleton.Skeleton that is used by the application for viewing an existing entry from the hierarchy.

The default is a Skeleton instance returned by _resolveSkel().

See also

addSkel(), editSkel(), _resolveSkel()

Returns:Returns a Skeleton instance for viewing an entry.
Return type:server.skeleton.Skeleton

List

class server.prototypes.list.List(moduleName, modulePath, *args, **kwargs)

List is a ViUR BasicApplication.

It is used for multiple data entities of the same kind, and needs to be sub-classed for individual modules.

Variables:
  • kindName (str) – Name of the kind of data entities that are managed by the application. This information is used to bind a specific server.skeleton.Skeleton-class to the application. For more information, refer to the function _resolveSkel().
  • adminInfo (dict | callable) – todo short info on how to use adminInfo.
add(*args, **kwargs)

Add a new 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

addSkel(), onItemAdded(), canAdd()

Returns:The rendered, added object of the entry, eventually with error hints.
Raises:server.errors.Unauthorized, if the current user does not have the required permissions.
Raises:server.errors.PreconditionFailed, if the skey could not be verified.
addSkel(*args, **kwargs)

Retrieve a new instance of a server.skeleton.Skeleton that is used by the application for adding an entry to the list.

The default is a Skeleton instance returned by _resolveSkel().

See also

viewSkel(), editSkel(), _resolveSkel()

Returns:Returns a Skeleton instance for adding an entry.
Return type:server.skeleton.Skeleton
canAdd()

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

add()

Returns:True, if adding entries is allowed, False otherwise.
Return type:bool
canDelete(skel)

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:skel (server.skeleton.Skeleton) – The Skeleton that should be deleted.

See also

delete()

Returns:True, if deleting entries is allowed, False otherwise.
Return type:bool
canEdit(skel)

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

edit()

Parameters:skel (server.skeleton.Skeleton) – The Skeleton that should be edited.
Returns:True, if editing entries is allowed, False otherwise.
Return type:bool
canPreview()

Access control function for preview permission.

Checks if the current user has the permission to preview an entry.

The default behavior is: - If no user is logged in, previewing is generally refused. - If the user has “root” access, previewing is generally allowed. - If the user has the modules “add” or “edit” permission (module-add, module-edit) enabled, previewing is allowed.

It should be overridden for module-specific behavior.

See also

preview()

Returns:True, if previewing entries is allowed, False otherwise.
Return type:bool
delete(key, skey, *args, **kwargs)

Delete an entry.

The function runs several access control checks on the data before it is deleted.

See also

canDelete(), editSkel(), onItemDeleted()

Returns:The rendered, deleted object of the entry.
Raises:server.errors.NotFound, when no entry with the given key was found.
Raises:server.errors.Unauthorized, if the current user does not have the required permissions.
Raises:server.errors.PreconditionFailed, if the skey could not be verified.
edit(*args, **kwargs)

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 entry is fetched by its entity key, which either is provided via kwargs[“key”], or as the first parameter in args. The function performs several access control checks on the requested entity before it is modified.

See also

editSkel(), onItemEdited(), canEdit()

Returns:The rendered, edited object of the entry, eventually with error hints.
Raises:server.errors.NotAcceptable, when no key is provided.
Raises:server.errors.NotFound, when no entry with the given key was found.
Raises:server.errors.Unauthorized, if the current user does not have the required permissions.
Raises:server.errors.PreconditionFailed, if the skey could not be verified.
editSkel(*args, **kwargs)

Retrieve a new instance of a server.skeleton.Skeleton that is used by the application for editing an existing entry from the list.

The default is a Skeleton instance returned by _resolveSkel().

See also

viewSkel(), editSkel(), _resolveSkel()

Returns:Returns a Skeleton instance for editing an entry.
Return type:server.skeleton.Skeleton
list(*args, **kwargs)

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(), server.db.mergeExternalFilter()

Returns:The rendered list objects for the matching entries.
Raises:server.errors.Unauthorized, if the current user does not have the required permissions.
listFilter(filter)

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:filter (server.db.Query) – Query which should be altered.
Returns:The altered filter, or None if access is not granted.
onItemAdded(skel)

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:skel (server.skeleton.Skeleton) – The Skeleton that has been added.

See also

add()

onItemDeleted(skel)

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.

Parameters:skel (server.skeleton.Skeleton) – The Skeleton that has been deleted.

See also

delete()

onItemEdited(skel)

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:skel (server.skeleton.Skeleton) – The Skeleton that has been modified.

See also

edit()

onItemViewed(skel)

Hook function that is called when viewing an entry.

It should be overridden for a module-specific behavior. The default is doing nothing.

Parameters:skel (server.skeleton.Skeleton) – The Skeleton that is viewed.

See also

view()

preview(skey, *args, **kwargs)

Renders data for an entry, without reading from the database. This function allows to preview an entry without writing it to the database.

Any entity values are provided via kwargs.

The function uses the viewTemplate of the application.

Returns:The rendered representation of the the supplied data.
view(*args, **kwargs)

Prepares and renders a single entry for viewing.

The entry is fetched by its entity key, which either is provided via kwargs[“key”], or as the first parameter in args. The function performs several access control checks on the requested entity before it is rendered.

See also

viewSkel(), canView(), onItemViewed()

Returns:The rendered representation of the requested entity.
Raises:server.errors.NotAcceptable, when no key is provided.
Raises:server.errors.NotFound, when no entry with the given key was found.
Raises:server.errors.Unauthorized, if the current user does not have the required permissions.
viewSkel(*args, **kwargs)

Retrieve a new instance of a server.skeleton.Skeleton that is used by the application for viewing an existing entry from the list.

The default is a Skeleton instance returned by _resolveSkel().

See also

addSkel(), editSkel(), _resolveSkel()

Returns:Returns a Skeleton instance for viewing an entry.
Return type:server.skeleton.Skeleton

Singleton

class server.prototypes.singleton.Singleton(moduleName, modulePath, *args, **kwargs)

Singleton is a ViUR BasicApplication.

It is used to store one single data entity, and needs to be sub-classed for individual modules.

Variables:
  • kindName (str) – Name of the kind of data entities that are managed by the application. This information is used to bind a specific server.skeleton.Skeleton-class to the application. For more information, refer to the function _resolveSkel().
  • adminInfo (dict | callable) – todo short info on how to use adminInfo.
canEdit()

Access control function for modification permission.

Checks if the current user has the permission to edit the singletons 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

edit()

Returns:True, if editing is allowed, False otherwise.
Return type:bool
canPreview()

Access control function for preview permission.

Checks if the current user has the permission to preview the singletons entry.

The default behavior is: - If no user is logged in, previewing is generally refused. - If the user has “root” access, previewing is generally allowed. - If the user has the modules “edit” permission (module-edit) enabled, previewing is allowed.

It should be overridden for a module-specific behavior.

See also

preview()

Returns:True, if previewing entries is allowed, False otherwise.
Return type:bool
canView()

Access control function for viewing permission.

Checks if the current user has the permission to view the singletons entry.

The default behavior is: - If no user is logged in, viewing is generally refused. - If the user has “root” access, viewing is generally allowed. - If the user has the modules “view” permission (module-view) enabled, viewing is allowed.

It should be overridden for a module-specific behavior.

See also

view()

Parameters:skel (server.skeleton.Skeleton) – The Skeleton that should be viewed.
Returns:True, if viewing is allowed, False otherwise.
Return type:bool
edit(*args, **kwargs)

Modify the existing entry, and render the entry, eventually with error notes on incorrect data.

The entry is fetched by its entity key, which either is provided via kwargs[“key”], or as the first parameter in args. The function performs several access control checks on the singleton’s entity before it is modified.

See also

editSkel(), onItemEdited(), canEdit()

Returns:The rendered, edited object of the entry, eventually with error hints.
Raises:server.errors.Unauthorized, if the current user does not have the required permissions.
Raises:server.errors.PreconditionFailed, if the skey could not be verified.
editSkel(*args, **kwargs)

Retrieve a new instance of a server.skeleton.Skeleton that is used by the application for editing the existing entry.

The default is a Skeleton instance returned by _resolveSkel().

See also

viewSkel(), editSkel(), _resolveSkel()

Returns:Returns a Skeleton instance for editing the entry.
Return type:server.skeleton.Skeleton
getContents()

Returns the entity of this singleton application as server.skeleton.Skeleton object.

Returns:The content as Skeleton provided by viewSkel().
getKey()

Returns the DB-Key for the current context.

This implementation provides one module-global key. It must return exactly one key at any given time in any given context.

Returns:Current context DB-key
Return type:str
onItemEdited(skel)

Hook function that is called after modifying the entry.

It should be overridden for a module-specific behavior. The default is writing a log entry.

Parameters:skel (server.skeleton.Skeleton) – The Skeleton that has been modified.

See also

edit()

onItemViewed(skel)

Hook function that is called when viewing an entry.

It should be overridden for a module-specific behavior. The default is doing nothing.

Parameters:skel (server.skeleton.Skeleton) – The Skeleton that is viewed.

See also

view()

preview(skey, *args, **kwargs)

Renders data for the entry, without reading it from the database. This function allows to preview the entry without writing it to the database.

Any entity values are provided via kwargs.

The function uses the viewTemplate of the application.

Returns:The rendered representation of the supplied data.
view(*args, **kwargs)

Prepares and renders the singleton entry for viewing.

The function performs several access control checks on the requested entity before it is rendered.

See also

viewSkel(), canView(), onItemViewed()

Returns:The rendered representation of the entity.
Raises:server.errors.NotFound, if there is no singleton entry existing, yet.
Raises:server.errors.Unauthorized, if the current user does not have the required permissions.
viewSkel(*args, **kwargs)

Retrieve a new instance of a server.skeleton.Skeleton that is used by the application for viewing the existing entry.

The default is a Skeleton instance returned by _resolveSkel().

See also

addSkel(), editSkel(), _resolveSkel()

Returns:Returns a Skeleton instance for viewing the singleton entry.
Return type:server.skeleton.Skeleton

Tree

class server.prototypes.tree.Tree(moduleName, modulePath, *args, **kwargs)

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 server.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.
add(skelType, node, *args, **kwargs)

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.

See also

onItemAdded(), canAdd()

Parameters:
  • skelType (str) – Defines the type of the new entry and may either be “node” or “leaf”.
  • node (str) – URL-safe key of the parent.
Returns:

The rendered, added object of the entry, eventually with error hints.

Raises:

server.errors.NotAcceptable, when no valid skelType was provided.

Raises:

server.errors.NotFound, when no valid node was found.

Raises:

server.errors.Unauthorized, if the current user does not have the required permissions.

Raises:

server.errors.PreconditionFailed, if the skey could not be verified.

canAdd(skelType, node)

Access control function for adding permission.

Checks if the current user has the permission to add a new entry to node.

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

add()

Parameters:
  • skelType (str) – Defines the type of the node that shall be added.
  • node (str) – URL-safe key of the parent node under which the element shall be added.
Returns:

True, if adding entries is allowed, False otherwise.

Return type:

bool

canDelete(skelType, skel)

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 (str) – Defines the type of the node that shall be deleted.
  • skel (server.skeleton.Skeleton) – The Skeleton that should be deleted.

See also

delete()

Returns:True, if deleting entries is allowed, False otherwise.
Return type:bool
canEdit(skelType, skel)

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

edit()

Parameters:
  • skelType (str) – Defines the type of the node that shall be modified.
  • skel (server.skeleton.Skeleton) – The Skeleton that should be edited.
Returns:

True, if editing entries is allowed, False otherwise.

Return type:

bool

canList(skelType, node)

Access control function for listing permission.

Checks if the current user has the permission to list the children of the given node.

The default behavior is: - If no user is logged in, listing is generally refused. - If the user has “root” access, listing is generally allowed. - If the user has the modules “view” permission (module-view) enabled, listing is allowed.

It should be overridden for a module-specific behavior.

See also

list()

Parameters:
  • skelType (str) – Defines the type of node.
  • node (str) – URL-safe key of the node.
Returns:

True, if listing is allowed, False otherwise.

Return type:

bool

canMove(skelType, node, destNode)

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 (str) – Defines the type of the node that shall be deleted.
  • node (str) – URL-safe key of the node to be moved.
  • node – URL-safe key of the node where node should be moved to.

See also

move()

Returns:True, if deleting entries is allowed, False otherwise.
Return type:bool
canView(skelType, skel)

Access control function for viewing permission.

Checks if the current user has the permission to view node.

The default behavior is: - If no user is logged in, viewing is generally refused. - If the user has “root” access, viewing is generally allowed. - If the user has the modules “view” permission (module-view) enabled, viewing is allowed.

It should be overridden for a module-specific behavior.

See also

view()

Parameters:
Returns:

True, if viewing is allowed, False otherwise.

Return type:

bool

delete(skelType, key, *args, **kwargs)

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

canDelete(), onItemDeleted()

Parameters:
  • skelType (str) – Defines the type of the entry that should be deleted and may either be “node” or “leaf”.
  • key (str) – URL-safe key of the item to be deleted.
Returns:

The rendered, deleted object of the entry.

Raises:

server.errors.NotFound, when no entry with the given key was found.

Raises:

server.errors.Unauthorized, if the current user does not have the required permissions.

Raises:

server.errors.PreconditionFailed, if the skey could not be verified.

deleteRecursive(nodeKey)

Recursively processes a delete request.

This will delete all entries which are children of nodeKey, except key nodeKey.

Parameters:key (str) – URL-safe key of the node which children should be deleted.
Returns:The number of deleted objects.
Return type:int
edit(skelType, key, skey='', *args, **kwargs)

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

onItemAdded(), canEdit()

Parameters:
  • skelType (str) – Defines the type of the entry that should be modified and may either be “node” or “leaf”.
  • key (str) – URL-safe key of the item to be edited.
Returns:

The rendered, modified object of the entry, eventually with error hints.

Raises:

server.errors.NotAcceptable, when no valid skelType was provided.

Raises:

server.errors.NotFound, when no valid node was found.

Raises:

server.errors.Unauthorized, if the current user does not have the required permissions.

Raises:

server.errors.PreconditionFailed, if the skey could not be verified.

ensureOwnModuleRootNode()

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.
Return type:server.db.Entity
ensureOwnUserRootNode()

Ensures, that an root-node for the current user exists. If no root-node exists yet, it will be created.

Returns:The entity of the root-node or None, if this was request was made by a guest.
Return type:server.db.Entity
getRootNode(subRepo)

Returns the root-root-node for a given (sub)-repo.

Parameters:subRepo (str) – URL-safe root-node key.
Returns:server.db.Entity
isOwnUserRootNode(repo)

Checks, if the given rootNode is owned by the current user.

Parameters:repo (str) – URL-safe key of the root-node.
Returns:True if the user owns this root-node, False otherwise.
Return type:bool
jinjaEnv(env)

Provides some additional Jinja2 template functions for tree applications.

These function are:

  • pathToKey() alias getPathToKey()

..warning:: It is important to call the super-class-function of Hierarchy when this function is overridden from a sub-classed module.

list(skelType, node, *args, **kwargs)

List the entries and directorys of the given skelType under the given node. Any other supplied parameters are interpreted as filters for the elements displayed.

See also

canList(), server.db.mergeExternalFilter()

Parameters:
  • skelType (str) – May either be “node” or “leaf”.
  • node (str) – URL-safe key of the parent.
Returns:

The rendered list objects for the matching entries.

Raises:

server.errors.Unauthorized, if the current user does not have the required permissions.

Raises:

server.errors.NotFound, if node could not be found.

Raises:

server.errors.NotAcceptable, if anything else than “node” or “leaf” is provided to skelType.

listRootNodes(name=None, *args, **kwargs)

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.
Return type:str
move(skelType, key, destNode, *args, **kwargs)

Move a node (including its contents) or a leaf to another node.

See also

canMove()

Parameters:
  • skelType (str) – Defines the type of the entry that should be moved and may either be “node” or “leaf”.
  • key (str) – URL-safe key of the item to be moved.
  • destNode (str) – URL-safe key of the destination node, which must be a node.
Returns:

The rendered, edited object of the entry.

Raises:

server.errors.NotFound, when no entry with the given key was found.

Raises:

server.errors.Unauthorized, if the current user does not have the required permissions.

Raises:

server.errors.PreconditionFailed, if the skey could not be verified.

onItemAdded(skel)

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:skel (server.skeleton.Skeleton) – The Skeleton that has been added.

See also

add()

onItemDeleted(skel)

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:skel (server.skeleton.Skeleton) – The Skeleton that has been deleted.

See also

delete()

onItemEdited(skel)

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:skel (server.skeleton.Skeleton) – The Skeleton that has been modified.

See also

edit()

onItemViewed(skel)

Hook function that is called when viewing an entry.

It should be overridden for a module-specific behavior. The default is doing nothing.

Parameters:skel (server.skeleton.Skeleton) – The Skeleton that is viewed.

See also

view()

pathToKey(key)

Returns the recursively expanded path through the Tree from the root-node to the given key.

Parameters:key (str) – URL-safe key of the destination node.
Returns:An nested dictionary with information about all nodes in the path from root to the given node key.
Return type:dict
updateParentRepo(parentNode, newRepoKey, depth=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 (str) – URL-safe key of the node which children should be fixed.
  • newNode (strg) – URL-safe key of the new repository.
  • depth (int) – Safety level depth preventing infinitive loops.
view(skelType, key, *args, **kwargs)

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.

See also

canView(), onItemViewed()

Returns:

The rendered representation of the requested entity.

Parameters:
  • skelType (str) – May either be “node” or “leaf”.
  • node (str) – URL-safe key of the parent.
Raises:

server.errors.NotAcceptable, when an incorrect skelType is provided.

Raises:

server.errors.NotFound, when no entry with the given key was found.

Raises:

server.errors.Unauthorized, if the current user does not have the required permissions.