core.prototypes.singleton
¶
Module Contents¶
Classes¶
Singleton module prototype. |
- class core.prototypes.singleton.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
- index()¶
- 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(action='view')¶
- 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.- Parameters:
action (viur.core.decorators.t.Optional[str]) –
- 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.
See also
- 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.
See also
- 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
- 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
- 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
- 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
- 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.