core.prototypes.singleton

Module Contents

Classes

Singleton

Singleton is a ViUR BasicApplication.

Attributes

admin

html

vi

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

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

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

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(self, *args, **kwargs)

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

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

See also

addSkel(), editSkel(), _resolveSkel()

Returns

Returns a Skeleton instance for viewing the singleton entry.

Return type

server.skeleton.Skeleton

editSkel(self, *args, **kwargs)

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

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

See also

viewSkel(), editSkel(), _resolveSkel()

Returns

Returns a Skeleton instance for editing the entry.

Return type

server.skeleton.Skeleton

preview(self, skey, *args, **kwargs)

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

Any entity values are provided via kwargs.

The function uses the viewTemplate of the application.

Returns

The rendered representation of the supplied data.

structure(self, *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.

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

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

Raises

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

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

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

Raises

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

getContents(self)

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

Returns

The content as Skeleton provided by viewSkel().

canPreview(self)

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

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

Access control function for viewing permission.

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

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

It should be overridden for a module-specific behavior.

See also

view()

Parameters

skel (server.skeleton.Skeleton) – The Skeleton that should be viewed.

Returns

True, if viewing is allowed, False otherwise.

Return type

bool

onEdit(self, skel)

Hook function that is called before editing an entry.

It can be overridden for a module-specific behavior.

Parameters

skel (server.skeleton.Skeleton) – The Skeleton that is going to be edited.

See also

edit(), onEdited()

onEdited(self, skel)

Hook function that is called after modifying the entry.

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

Parameters

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

See also

edit(), onEdit()

onView(self, skel)

Hook function that is called when viewing an entry.

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

Parameters

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

See also

view()

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