core.prototypes

Submodules

Package Contents

Classes

List

List module prototype.

Singleton

Singleton module prototype.

Tree

Tree module prototype.

TreeSkel

This is a container-object holding information about one database entity.

Functions

__getattr__(attr)

class core.prototypes.List(*args, **kwargs)

Bases: core.prototypes.skelmodule.SkelModule

List module prototype.

The list module prototype handles datasets in a flat list. It can be extended to filters and views to provide various use-cases.

It is undoubtedly the most frequently used prototype in any ViUR project.

handler = 'list'
accessRights = ('add', 'edit', 'view', 'delete', 'manage')
default_order: core.prototypes.skelmodule.DEFAULT_ORDER_TYPE

Allows to specify a default order for this module, which is applied when no other order is specified.

Setting a default_order might result in the requirement of additional indexes, which are being raised and must be specified.

viewSkel(*args, **kwargs)

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

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

This SkeletonInstance can be post-processed (just returning a subskel or manually removing single bones) - which is the recommended way to ensure a given user cannot see certain fields. A Jinja-Template may choose not to display certain bones, but if the json or xml render is attached (or the user can use the vi or admin render) he could still see all values. This also prevents the user from filtering by these bones, so no binary search is possible.

See also

addSkel(), editSkel(), baseSkel()

Returns:

Returns a Skeleton instance for viewing an entry.

Return type:

viur.core.skeleton.SkeletonInstance

addSkel(*args, **kwargs)

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().

Like in viewSkel(), the skeleton can be post-processed. Bones that are being removed aren’t visible and cannot be set, but it’s also possible to just set a bone to readOnly (revealing it’s value to the user, but preventing any modification. It’s possible to pre-set values on that skeleton (and if that bone is readOnly, enforcing these values).

See also

viewSkel(), editSkel(), baseSkel()

Returns:

Returns a Skeleton instance for adding an entry.

Return type:

viur.core.skeleton.SkeletonInstance

editSkel(*args, **kwargs)

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().

Like in viewSkel(), the skeleton can be post-processed. Bones that are being removed aren’t visible and cannot be set, but it’s also possible to just set a bone to readOnly (revealing it’s value to the user, but preventing any modification.

See also

viewSkel(), editSkel(), baseSkel()

Returns:

Returns a Skeleton instance for editing an entry.

Return type:

viur.core.skeleton.SkeletonInstance

cloneSkel(*args, **kwargs)

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

The default is a SkeletonInstance returned by baseSkel().

Like in viewSkel(), the skeleton can be post-processed. Bones that are being removed aren’t visible and cannot be set, but it’s also possible to just set a bone to readOnly (revealing it’s value to the user, but preventing any modification.

See also

viewSkel(), editSkel(), baseSkel()

Returns:

Returns a SkeletonInstance for editing an entry.

Return type:

viur.core.skeleton.SkeletonInstance

preview(*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 supplied data.

Return type:

viur.core.decorators.t.Any

structure(*args, **kwargs)
Returns:

Returns the structure of our skeleton as used in list/view. Values are the defaultValues set in each bone.

Raises:

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

Return type:

viur.core.decorators.t.Any

view(key, *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.

Returns:

The rendered representation of the requested entity.

Raises:

viur.core.errors.NotAcceptable, when no key 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.

Parameters:

key (viur.core.db.Key | int | str) –

Return type:

viur.core.decorators.t.Any

list(*args, **kwargs)

Prepares and renders a list of entries.

All supplied parameters are interpreted as filters for the elements displayed.

Unlike other modules in ViUR, 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.

Return type:

viur.core.decorators.t.Any

edit(key, *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.

Returns:

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

Raises:

viur.core.errors.NotAcceptable, when no key 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.

Raises:

viur.core.errors.PreconditionFailed, if the skey could not be verified.

Parameters:

key (viur.core.db.Key | int | str) –

Return type:

viur.core.decorators.t.Any

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.

Returns:

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

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.

Return type:

viur.core.decorators.t.Any

delete(key, *args, **kwargs)

Delete an entry.

The function runs several access control checks on the data before it is 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.

Parameters:

key (viur.core.db.Key | int | str) –

Return type:

viur.core.decorators.t.Any

index(*args, **kwargs)

Default, SEO-Friendly fallback for view and list.

Parameters:
  • args – The first argument - if provided - is interpreted as seoKey.

  • kwargs – Used for the fallback list.

Returns:

The rendered entity or list.

Return type:

viur.core.decorators.t.Any

getDefaultListParams()
clone(key, **kwargs)

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

Parameters:

key (viur.core.db.Key | str | int) – URL-safe key of the item to be edited.

Returns:

The cloned 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 entry to clone from was found.

Raises:

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

listFilter(query)

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 (viur.core.db.Query) – Query which should be altered.

Returns:

The altered filter, or None if access is not granted.

Return type:

viur.core.decorators.t.Optional[viur.core.db.Query]

canView(skel)

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

Parameters:

skel (viur.core.skeleton.SkeletonInstance) –

Return type:

bool

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

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

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 (viur.core.skeleton.SkeletonInstance) – The Skeleton that should be edited.

Returns:

True, if editing 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 (viur.core.skeleton.SkeletonInstance) – The Skeleton that should be deleted.

Return type:

bool

See also

delete()

Returns:

True, if deleting entries is allowed, False otherwise.

Parameters:

skel (viur.core.skeleton.SkeletonInstance) –

Return type:

bool

onAdd(skel)

Hook function that is called before adding an entry.

It can be overridden for a module-specific behavior.

Parameters:

skel (viur.core.skeleton.SkeletonInstance) – The Skeleton that is going to be added.

See also

add(), onAdded()

onAdded(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 (viur.core.skeleton.SkeletonInstance) – The Skeleton that has been added.

See also

add(), , onAdd()

onEdit(skel)

Hook function that is called before editing an entry.

It can be overridden for a module-specific behavior.

Parameters:

skel (viur.core.skeleton.SkeletonInstance) – The Skeleton that is going to be edited.

See also

edit(), onEdited()

onEdited(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 (viur.core.skeleton.SkeletonInstance) – The Skeleton that has been modified.

See also

edit(), onEdit()

onView(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 (viur.core.skeleton.SkeletonInstance) – The Skeleton that is viewed.

See also

view()

onDelete(skel)

Hook function that is called before deleting an entry.

It can be overridden for a module-specific behavior.

Parameters:

skel (viur.core.skeleton.SkeletonInstance) – The Skeleton that is going to be deleted.

See also

delete(), onDeleted()

onDeleted(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 (viur.core.skeleton.SkeletonInstance) – The Skeleton that has been deleted.

See also

delete(), onDelete()

onClone(skel, src_skel)

Hook function that is called before cloning an entry.

It can be overwritten to a module-specific behavior.

Parameters:
  • skel (viur.core.skeleton.SkeletonInstance) – The new SkeletonInstance that is being created.

  • src_skel (viur.core.skeleton.SkeletonInstance) – The source SkeletonInstance skel is cloned from.

See also

clone(), onCloned()

onCloned(skel, src_skel)

Hook function that is called after cloning an entry.

It can be overwritten to a module-specific behavior.

Parameters:
  • skel (viur.core.skeleton.SkeletonInstance) – The new SkeletonInstance that was created.

  • src_skel (viur.core.skeleton.SkeletonInstance) – The source SkeletonInstance skel was cloned from.

See also

clone(), onClone()

class core.prototypes.Singleton(*args, **kwargs)

Bases: core.prototypes.skelmodule.SkelModule

Singleton module prototype.

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

handler = 'singleton'
accessRights = ('edit', 'view', 'manage')
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

viewSkel(*args, **kwargs)

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

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

See also

addSkel(), editSkel(), baseSkel()

Returns:

Returns a Skeleton instance for viewing the singleton entry.

Return type:

viur.core.skeleton.SkeletonInstance

editSkel(*args, **kwargs)

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

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

See also

viewSkel(), editSkel(), baseSkel()

Returns:

Returns a Skeleton instance for editing the entry.

Return type:

viur.core.skeleton.SkeletonInstance

preview(*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.

Return type:

viur.core.decorators.t.Any

structure(*args, **kwargs)
Returns:

Returns the structure of our skeleton as used in list/view. Values are the defaultValues set in each bone.

Raises:

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

Return type:

viur.core.decorators.t.Any

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.

Returns:

The rendered representation of the entity.

Raises:

viur.core.errors.NotFound, if there is no singleton entry existing, yet.

Raises:

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

Return type:

viur.core.decorators.t.Any

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.

Returns:

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

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.

Return type:

viur.core.decorators.t.Any

getContents()

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

Returns:

The content as Skeleton provided by viewSkel().

Return type:

viur.core.skeleton.SkeletonInstance | None

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

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

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()

Returns:

True, if viewing is allowed, False otherwise.

Return type:

bool

onEdit(skel)

Hook function that is called before editing an entry.

It can be overridden for a module-specific behavior.

Parameters:

skel (viur.core.skeleton.SkeletonInstance) – The Skeleton that is going to be edited.

See also

edit(), onEdited()

onEdited(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 (viur.core.skeleton.SkeletonInstance) – The Skeleton that has been modified.

See also

edit(), onEdit()

onView(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 (viur.core.skeleton.SkeletonInstance) – The Skeleton that is being viewed.

See also

view()

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

Bases: core.prototypes.skelmodule.SkelModule

Tree module prototype.

It is used for hierarchical structures, either as a tree with nodes and leafs, or as a hierarchy with nodes only.

property handler
accessRights = ('add', 'edit', 'view', 'delete', 'manage')
nodeSkelCls
leafSkelCls
default_order: core.prototypes.skelmodule.DEFAULT_ORDER_TYPE = 'sortindex'

Allows to specify a default order for this module, which is applied when no other order is specified.

Setting a default_order might result in the requirement of additional indexes, which are being raised and must be specified.

_checkSkelType(skelType)

Checks for correct skelType.

Either returns the type provided, or None in case it is invalid.

Parameters:

skelType (viur.core.decorators.t.Any) –

Return type:

viur.core.decorators.t.Optional[SkelType]

_resolveSkelCls(skelType, *args, **kwargs)

Retrieve the generally associated viur.core.skeleton.Skeleton that is used by the application.

This is either be defined by the member variable kindName or by a Skeleton named like the application class in lower-case order.

If this behavior is not wanted, it can be definitely overridden by defining module-specific viewSkel(), addSkel(), or editSkel() functions, or by overriding this function in general.

Returns:

Returns a Skeleton class that matches the application.

Parameters:

skelType (SkelType) –

Return type:

viur.core.decorators.t.Type[viur.core.skeleton.Skeleton]

baseSkel(skelType, *args, **kwargs)

Return unmodified base skeleton for the given skelType.

Parameters:

skelType (SkelType) –

Return type:

viur.core.skeleton.SkeletonInstance

viewSkel(skelType, *args, **kwargs)

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

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

Returns:

Returns a Skeleton instance for viewing an entry.

Parameters:

skelType (SkelType) –

Return type:

viur.core.skeleton.SkeletonInstance

addSkel(skelType, *args, **kwargs)

Retrieve a new instance of a viur.core.skeleton.Skeleton that is used by the application for adding an entry to the tree.

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

Returns:

Returns a Skeleton instance for adding an entry.

Parameters:

skelType (SkelType) –

Return type:

viur.core.skeleton.SkeletonInstance

editSkel(skelType, *args, **kwargs)

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

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

Returns:

Returns a Skeleton instance for editing an entry.

Parameters:

skelType (SkelType) –

Return type:

viur.core.skeleton.SkeletonInstance

cloneSkel(skelType, *args, **kwargs)

Retrieve a new viur.core.skeleton.SkeletonInstance that is used by the application for cloning an existing entry of the tree.

The default is a SkeletonInstance returned by baseSkel().

Returns:

Returns a SkeletonInstance for cloning an entry.

Parameters:

skelType (SkelType) –

Return type:

viur.core.skeleton.SkeletonInstance

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:

viur.core.db.Entity

getAvailableRootNodes(*args, **kwargs)

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:

# Example
def getAvailableRootNodes(self, *args, **kwargs):
    q = db.Query(self.rootKindName)
    ret = [{"key": str(e.key()),
        "name": e.get("name", str(e.key().id_or_name()))} #FIXME
        for e in q.run(limit=25)]
    return ret
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.

Return type:

list[dict[viur.core.decorators.t.Literal[name, key], str]]

getRootNode(key)

Returns the root-node for a given child.

Parameters:

key (viur.core.db.Key | str) – Key of the child node entry.

Returns:

The skeleton of the root-node.

Return type:

viur.core.skeleton.SkeletonInstance | None

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.

  • newRepoKey (str) – URL-safe key of the new repository.

  • depth (int) – Safety level depth preventing infinitive loops.

pathToKey(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.

Parameters:

key (viur.core.db.Key) –

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:

viur.core.decorators.t.Any

list(skelType, *args, **kwargs)

Prepares and renders a list of entries.

All supplied parameters are interpreted as filters for the elements displayed.

Unlike other module prototypes in ViUR, 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.

Parameters:

skelType (SkelType) –

Return type:

viur.core.decorators.t.Any

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

Parameters:

skelType (SkelType) –

Return type:

viur.core.decorators.t.Any

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(), onView()

Returns:

The rendered representation of the requested entity.

Parameters:
  • skelType (SkelType) – May either be “node” or “leaf”.

  • key (viur.core.db.Key | int | str) – 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.

Return type:

viur.core.decorators.t.Any

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

canAdd(), onAdd(), , onAdded()

Parameters:
  • skelType (SkelType) – Defines the type of the new entry and may either be “node” or “leaf”.

  • node (viur.core.db.Key | int | str) – 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.

Return type:

viur.core.decorators.t.Any

edit(skelType, key, *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.

Parameters:
  • skelType (SkelType) – Defines the type of the entry that should be modified and may either be “node” or “leaf”.

  • key (viur.core.db.Key | int | str) – 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.

Return type:

viur.core.decorators.t.Any

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.

Parameters:
  • skelType (SkelType) – 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:

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.

Return type:

viur.core.decorators.t.Any

deleteRecursive(parentKey)

Recursively processes a delete request.

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

Parameters:

parentKey (str) – URL-safe key of the node which children should be deleted.

move(skelType, key, parentNode, *args, **kwargs)

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

See also

canMove()

Parameters:
  • skelType (SkelType) – Defines the type of the entry that should be moved and may either be “node” or “leaf”.

  • key (viur.core.db.Key | int | str) – URL-safe key of the item to be moved.

  • parentNode (str) – URL-safe key of the destination node, which must be a node.

  • skey – The CSRF security key.

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.

Return type:

str

clone(skelType, key, **kwargs)

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

Parameters:
  • skelType (SkelType) – Defines the type of the entry that should be cloned and may either be “node” or “leaf”.

  • key (viur.core.db.Key | str | int) – URL-safe key of the item to be edited.

Returns:

The cloned 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 entry to clone from was found.

Raises:

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

listFilter(query)

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 (viur.core.db.Query) – Query which should be altered.

Returns:

The altered filter, or None if access is not granted.

Return type:

viur.core.decorators.t.Optional[viur.core.db.Query]

canView(skelType, skel)

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

Parameters:
  • skelType (SkelType) –

  • skel (viur.core.skeleton.SkeletonInstance) –

Return type:

bool

canAdd(skelType, parentNodeSkel)

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()

Parameters:
  • skelType (SkelType) – Defines the type of the node that should be added.

  • parentNodeSkel (viur.core.decorators.t.Optional[viur.core.skeleton.SkeletonInstance]) – The parent node where a new entry should be added.

Returns:

True, if adding 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 (SkelType) – Defines the type of the node that should be edited.

  • skel (viur.core.skeleton.SkeletonInstance) – The Skeleton that should be edited.

Returns:

True, if editing 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 (SkelType) – Defines the type of the node that should be deleted.

  • skel (viur.core.skeleton.SkeletonInstance) – The Skeleton that should be deleted.

Return type:

bool

See also

delete()

Returns:

True, if deleting entries is allowed, False otherwise.

Parameters:
  • skelType (SkelType) –

  • skel (viur.core.skeleton.SkeletonInstance) –

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 (SkelType) – Defines the type of the node that shall be deleted.

  • node (viur.core.skeleton.SkeletonInstance) – URL-safe key of the node to be moved.

  • destNode (viur.core.skeleton.SkeletonInstance) – URL-safe key of the node where node should be moved to.

Return type:

bool

See also

move()

Returns:

True, if deleting entries is allowed, False otherwise.

Parameters:
  • skelType (SkelType) –

  • node (viur.core.skeleton.SkeletonInstance) –

  • destNode (viur.core.skeleton.SkeletonInstance) –

Return type:

bool

onAdd(skelType, skel)

Hook function that is called before adding an entry.

It can be overridden for a module-specific behavior.

Parameters:
  • skelType (SkelType) – Defines the type of the node that shall be added.

  • skel (viur.core.skeleton.SkeletonInstance) – The Skeleton that is going to be added.

See also

add(), onAdded()

onAdded(skelType, 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:
  • skelType (SkelType) – Defines the type of the node that has been added.

  • skel (viur.core.skeleton.SkeletonInstance) – The Skeleton that has been added.

See also

add(), onAdd()

onEdit(skelType, skel)

Hook function that is called before editing an entry.

It can be overridden for a module-specific behavior.

Parameters:
  • skelType (SkelType) – Defines the type of the node that shall be edited.

  • skel (viur.core.skeleton.SkeletonInstance) – The Skeleton that is going to be edited.

See also

edit(), onEdited()

onEdited(skelType, 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:
  • skelType (SkelType) – Defines the type of the node that has been edited.

  • skel (viur.core.skeleton.SkeletonInstance) – The Skeleton that has been modified.

See also

edit(), onEdit()

onView(skelType, 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:
  • skelType (SkelType) – Defines the type of the node that is viewed.

  • skel (viur.core.skeleton.SkeletonInstance) – The Skeleton that is viewed.

See also

view()

onDelete(skelType, skel)

Hook function that is called before deleting an entry.

It can be overridden for a module-specific behavior.

Parameters:
  • skelType (SkelType) – Defines the type of the node that shall be deleted.

  • skel (viur.core.skeleton.SkeletonInstance) – The Skeleton that is going to be deleted.

See also

delete(), onDeleted()

onDeleted(skelType, 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:
  • skelType (SkelType) – Defines the type of the node that is deleted.

  • skel (viur.core.skeleton.SkeletonInstance) – The Skeleton that has been deleted.

See also

delete(), onDelete()

onClone(skelType, skel, src_skel)

Hook function that is called before cloning an entry.

It can be overwritten to a module-specific behavior.

Parameters:
  • skelType (SkelType) – Defines the type of the node that is cloned.

  • skel (viur.core.skeleton.SkeletonInstance) – The new SkeletonInstance that is being created.

  • src_skel (viur.core.skeleton.SkeletonInstance) – The source SkeletonInstance skel is cloned from.

See also

clone(), onCloned()

_clone_recursive(skel_type, src_key, target_key, target_repo, cursor=None)

Helper function which is used by default onCloned() to clone a recursive structure.

Parameters:
  • skel_type (SkelType) –

  • src_key (viur.core.db.Key) –

  • target_key (viur.core.db.Key) –

  • target_repo (viur.core.db.Key) –

onCloned(skelType, skel, src_skel)

Hook function that is called after cloning an entry.

It can be overwritten to a module-specific behavior.

By default, when cloning a “node”, this function calls _clone_recursive() which recursively clones the entire structure below this node in the background. If this is not wanted, or wanted by a specific setting, overwrite this function without a super-call.

Parameters:
  • skelType (SkelType) – Defines the type of the node that is cloned.

  • skel (viur.core.skeleton.SkeletonInstance) – The new SkeletonInstance that was created.

  • src_skel (viur.core.skeleton.SkeletonInstance) – The source SkeletonInstance skel was cloned from.

See also

clone(), onClone()

class core.prototypes.TreeSkel(*args, **kwargs)

Bases: viur.core.skeleton.Skeleton

This is a container-object holding information about one database entity.

It has to be sub-classed with individual information about the kindName of the entities and its specific data attributes, the so called bones. The Skeleton stores its bones in an OrderedDict-Instance, so the definition order of the contained bones remains constant.

Variables:
  • key (server.bones.BaseBone) – This bone stores the current database key of this entity. Assigning to this bones value is dangerous and does not affect the actual key its stored in.

  • creationdate (server.bones.DateBone) – The date and time where this entity has been created.

  • changedate (server.bones.DateBone) – The date and time of the last change to this entity.

parententry
parentrepo
sortindex
classmethod refresh(skelValues)

Refresh the bones current content.

This function causes a refresh of all relational bones and their associated information.

core.prototypes.__getattr__(attr)