core.prototypes.list

Module Contents

Classes

List

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

Attributes

admin

html

vi

class core.prototypes.list.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()

core.prototypes.list.admin = True
core.prototypes.list.html = True
core.prototypes.list.vi = True