core.prototypes.singleton
¶
Module Contents¶
Classes¶
Singleton is a ViUR BasicApplication. |
- 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
viur.core.skeleton.Skeleton
-class to the application. For more information, refer to the functionbaseSkel()
.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.
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.
- 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.
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.
- getContents() viur.core.skeleton.SkeletonInstance | None ¶
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
- 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
- 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
- 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
- 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.