core.prototypes

Submodules

Package Contents

Classes

BasicApplication

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

List

The list prototype will only handle a single kind and arrange it's entities in a flat list.

Singleton

Singleton is a ViUR BasicApplication.

Tree

Tree is a ViUR BasicApplication.

TreeSkel

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

Bases: object

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

kindName :str

Name of the datastore kind that’s going to be handled by this application. This information is used to bind a specific viur.core.skeleton.Skeleton-class to this application. For more information, refer to the function _resolveSkelCls().

adminInfo :Union[Dict[str, Any], Callable]

A dict holding the information necessary for the Vi/Admin to handle this module. If set to None, this module will be ignored by the frontend. The currently supported values are:

name: str

Human-readable module name that will be shown in Vi/Admin

handler: str (list, tree or singleton):

Which (proto-)type is used, to the frontend can initialize it handler correctly.

icon: str

(Optional) The name (eg “icon-add”) or a path relative the the project (eg. /static/icons/viur.svg) for the icon used in the UI for that module.

columns: List[str]

(Optional) List of columns (bone names) that are displayed by default. Used only for the list handler.

filter: Dict[str, str]

(Optional) Dictionary of additional parameters that will be send along when fetching entities from the server. Can be used to filter the entities being displayed on the client-side.

display: str (“default”, “hidden” or “group”)

(Optional) “hidden” will hide the module in the main bar (itwill not be accessible directly, however it’s registered with the frontend so it can be used in a relational bone). “group” will show this module in the main bar, but it will not be clickable. Clicking it will just try to expand it (assuming there are additional views defined).

preview: Union[str, Dict[str, str]]

(Optional) A url that will be opened in a new tab and is expected to display the entity selected in the table. Can be “/{{module}}/view/{{key}}”, with {{module}} and {{key}} getting replaced as needed. If more than one preview-url is needed, supply a dictionary where the key is the URL and the value the description shown to the user.

views: List[Dict[str, Any]]

(Optional) List of nested adminInfo like dictionaries. Used to define additional views on the module. Useful f.e. for an order module, where you want separate list of “payed orders”, “unpayed orders”, “orders waiting for shipment”, etc. If such views are defined, the top-level entry in the menu bar will expand if clicked, revealing these additional filters.

actions: List[str]

(Optional) List of actions supported by this modules. Actions can be defined by the frontend (like “add”, “edit”, “delete” or “preview”); it can be an action defined by a plugin loaded by the frontend; or it can be a so called “server side action” (see “customActions” below)

customActions: Dict[str, dict]

(Optional) A mapping of names of server-defined actions that can be used in the actions list above to their definition dictionary. See …. for more details.

disabledActions: List[str, dict]

(Optional) A list of disabled actions. The frontend will inject default actions like add or edit even if they’re not listed in actions. Listing them here will prevent that. It’s up to the frontend to decide if that action won’t be visible at all or it’s button just being disabled.

sortIndex: int

(Optional) Defines the order in which the modules will appear in the main bar in ascrending order.

indexedBones: List[str]

(Optional) List of bones, for which an (composite?) index exists in this view. This allows the fronted to signal the user that a given list can be sorted or filtered by this bone. If no additional filters are enforced by the listFilter and filter is not set, this should be all bones which are marked as indexed.

changeInvalidates: List[str]

(Optional) A list of module-names which depend on the entities handled from this module. This allows the frontend to invalidate any caches in these depended modules if the data in this module changes. Example: This module may be a list-module handling the file_rootNode entities for the file module, so a edit/add/deletion action on this module should be reflected in the rootNode-selector in the file-module itself. In this case, this property should be set to ["file"].

moduleGroup: str

(Optional) If set, should be a key of a moduleGroup defined in …. .

editViews: Dict[str, Any]

(Optional) If set, will embed another list-widget in the edit forms for a given entity. See …. for more details.

If this is a function, it must take no parameters and return the dictionary as shown above. This can be used to customize the appearance of the Vi/Admin to individual users.

accessRights :List[str]

If set, a list of access rights (like add, edit, delete) that this module may support. These will be prefixed on instance startup with the actual module name (becomming file-add, file-edit etc) and registered in viur.core.config.conf["viur.accessRights"] so these will be available on the access bone in user/add or user/edit.

_resolveSkelCls(*args, **kwargs) Type[viur.core.skeleton.Skeleton]

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.

baseSkel(*args, **kwargs) viur.core.skeleton.SkeletonInstance

Returns an instance of an unmodified base skeleton for this module.

This function should only be used in cases where a full, unmodified skeleton of the module is required, e.g. for administrative or maintenance purposes.

By default, baseSkel is used by viewSkel(), addSkel(), and editSkel().

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

Bases: viur.core.prototypes.BasicApplication

The list prototype will only handle a single kind and arrange it’s entities in a flat list. This list can be filtered and/or sorted but there is no hierarchy/relationship between the items in that list.

accessRights = ['add', 'edit', 'view', 'delete']
adminInfo()
viewSkel(*args, **kwargs) viur.core.skeleton.SkeletonInstance

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.

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

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.

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

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.

preview(skey: str, *args, **kwargs) Any

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.

structure(*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.Unauthorized, if the current user does not have the required permissions.

view(*args, **kwargs) Any

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.

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

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

add(*args, **kwargs) Any

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.

delete(key: str, skey, *args, **kwargs) Any

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.

index(*args, **kwargs) Any

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.

getDefaultListParams()
listFilter(query: viur.core.db.Query) Optional[viur.core.db.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 – Query which should be altered.

Returns

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

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

add()

Returns

True, if adding entries is allowed, False otherwise.

canPreview() bool

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.

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

edit()

Parameters

skel – The Skeleton that should be edited.

Returns

True, if editing entries is allowed, False otherwise.

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

skel – The Skeleton that should be deleted.

See also

delete()

Returns

True, if deleting entries is allowed, False otherwise.

onAdd(skel: viur.core.skeleton.SkeletonInstance)

Hook function that is called before adding an entry.

It can be overridden for a module-specific behavior.

Parameters

skel – The Skeleton that is going to be added.

See also

add(), onAdded()

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

skel – The Skeleton that has been added.

See also

add(), , onAdd()

onEdit(skel: viur.core.skeleton.SkeletonInstance)

Hook function that is called before editing an entry.

It can be overridden for a module-specific behavior.

Parameters

skel – The Skeleton that is going to be edited.

See also

edit(), onEdited()

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

skel – The Skeleton that has been modified.

See also

edit(), onEdit()

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

skel – The Skeleton that is viewed.

See also

view()

onDelete(skel: viur.core.skeleton.SkeletonInstance)

Hook function that is called before deleting an entry.

It can be overridden for a module-specific behavior.

Parameters

skel – The Skeleton that is going to be deleted.

See also

delete(), onDeleted()

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

Parameters

skel – The Skeleton that has been deleted.

See also

delete(), onDelete()

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

Bases: viur.core.prototypes.BasicApplication

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 viur.core.skeleton.Skeleton-class to the application. For more information, refer to the function baseSkel().

  • adminInfo (dict | callable) – todo short info on how to use adminInfo.

accessRights = ['edit', 'view']
adminInfo()
getKey() str

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

viewSkel(*args, **kwargs) viur.core.skeleton.SkeletonInstance

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.

editSkel(*args, **kwargs) viur.core.skeleton.SkeletonInstance

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.

preview(skey: str, *args, **kwargs) Any

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.

structure(*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.Unauthorized, if the current user does not have the required permissions.

view(*args, **kwargs) Any

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.

edit(*args, **kwargs) Any

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.

getContents() Optional[viur.core.skeleton.SkeletonInstance]

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

Returns

The content as Skeleton provided by viewSkel().

canPreview() bool

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.

canEdit() bool

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.

canView() bool

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.

onEdit(skel: viur.core.skeleton.SkeletonInstance)

Hook function that is called before editing an entry.

It can be overridden for a module-specific behavior.

Parameters

skel – The Skeleton that is going to be edited.

See also

edit(), onEdited()

onEdited(skel: viur.core.skeleton.SkeletonInstance)

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 – The Skeleton that has been modified.

See also

edit(), onEdit()

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

skel – The Skeleton that is being viewed.

See also

view()

class core.prototypes.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) Optional[SkelType]

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.

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

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

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

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

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.

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.

See also

canView(), onView()

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.

See also

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

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.

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.

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

canMove()

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) Optional[viur.core.db.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 – 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: Optional[viur.core.skeleton.SkeletonInstance]) 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

add()

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

edit()

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

delete()

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

move()

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.

See also

add(), onAdded()

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.

See also

add(), onAdd()

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

edit(), onEdited()

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.

See also

edit(), onEdit()

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

view()

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

delete(), onDeleted()

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

delete(), onDelete()

class core.prototypes.TreeSkel

Bases: viur.core.skeleton.Skeleton

parententry
parentrepo
sortindex
classmethod refresh(skelValues)