core.skeleton.meta¶
Attributes¶
Classes¶
This is the metaclass for Skeletons. |
|
This is the metaclass for Skeletons. |
|
This is a container-object holding information about one database entity. |
Module Contents¶
- core.skeleton.meta._UNDEFINED_KINDNAME¶
- core.skeleton.meta.ABSTRACT_SKEL_CLS_SUFFIX = 'AbstractSkel'¶
- class core.skeleton.meta.MetaBaseSkel(name, bases, dct, **kwargs)¶
Bases:
typeThis is the metaclass for Skeletons. It is used to enforce several restrictions on bone names, etc.
- _skelCache¶
- _allSkelClasses¶
- __reserved_keywords¶
- __allowed_chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'¶
- static generate_bonemap(cls)¶
Recursively constructs a dict of bones from
- __setattr__(key, value)¶
- class core.skeleton.meta.MetaSkel(name, bases, dct, **kwargs)¶
Bases:
MetaBaseSkelThis is the metaclass for Skeletons. It is used to enforce several restrictions on bone names, etc.
- class core.skeleton.meta.BaseSkeleton¶
Bases:
objectThis is a container-object holding information about one database entity.
It has to be sub-classed with individual information about the kindName of the entities and its specific data attributes, the so called bones. The Skeleton stores its bones in an
OrderedDict-Instance, so the definition order of the contained bones remains constant.- Variables:
key (server.bones.BaseBone) – This bone stores the current database key of this entity. Assigning to this bones value is dangerous and does not affect the actual key its stored in.
creationdate (server.bones.DateBone) – The date and time where this entity has been created.
changedate (server.bones.DateBone) – The date and time of the last change to this entity.
- __viurBaseSkeletonMarker__ = True¶
- boneMap = None¶
- classmethod subSkel(*subskel_names, fullClone=False, **kwargs)¶
- Parameters:
fullClone (bool)
- Return type:
- classmethod subskel(*names, bones=(), clone=False)¶
Creates a new sub-skeleton from the current skeleton.
A sub-skeleton is a copy of the original skeleton, containing only a subset of its bones.
Sub-skeletons can either be defined using the the subSkels property of the Skeleton object, or freely by giving patterns for bone names which shall be part of the sub-skeleton.
Giving names as parameter merges the bones of all Skeleton.subSkels-configurations together. This is the usual behavior. By passing multiple sub-skeleton names to this function, a sub-skeleton with the union of all bones of the specified sub-skeletons is returned. If an entry called “*” exists in the subSkels-dictionary, the bones listed in this entry will always be part of the generated sub-skeleton.
Given the bones parameter allows to freely specify a sub-skeleton; One specialty here is, that the order of the bones can also be changed in this mode. This mode is the new way of defining sub-skeletons, and might become the primary way to define sub-skeletons in future.
Both modes (1 + 2) can be combined, but then the original order of the bones is kept.
The “key” bone is automatically available in each sub-skeleton.
An fnmatch-compatible wildcard pattern is allowed both in the subSkels-bone-list and the free bone list.
Example (TodoSkel is the example skeleton from viur-base): ```py # legacy mode (see 1) subskel = TodoSkel.subskel(“add”) # creates subskel: key, firstname, lastname, subject
# free mode (see 2) allows to specify a different order! subskel = TodoSkel.subskel(bones=(“subject”, “message”, “*stname”)) # creates subskel: key, subject, message, firstname, lastname
# mixed mode (see 3) subskel = TodoSkel.subskel(“add”, bones=(“message”, )) # creates subskel: key, firstname, lastname, subject, message ```
- Parameters:
bones (Iterable[str]) – Allows to specify an iterator of bone names (more precisely, fnmatch-wildards) which allow to freely define a subskel. If only this parameter is given, the order of the specification also defines, the order of the list. Otherwise, the original order as defined in the skeleton is kept.
clone (bool) – If set True, performs a cloning of the used bone map, to be entirely stand-alone.
names (str)
- Returns:
The sub-skeleton of the specified type.
- Return type:
- classmethod setSystemInitialized()¶
- classmethod setBoneValue(skel, boneName, value, append=False, language=None)¶
Allows for setting a bones value without calling fromClient or assigning a value directly. Sanity-Checks are performed; if the value is invalid, that bone flips back to its original (default) value and false is returned.
- Parameters:
boneName (str) – The name of the bone to be modified
value (Any) – The value that should be assigned. It’s type depends on the type of that bone
append (bool) – If True, the given value is appended to the values of that bone instead of replacing it. Only supported on bones with multiple=True
language (Optional[str]) – Language to set
skel (SkeletonInstance)
- Returns:
Wherever that operation succeeded or not.
- Return type:
bool
- classmethod fromClient(skel, data, *, amend=False, ignore=None)¶
Load supplied data into Skeleton.
This function works similar to
setValues(), except that the values retrieved from data are checked against the bones and their validity checks.Even if this function returns False, all bones are guaranteed to be in a valid state. The ones which have been read correctly are set to their valid values; Bones with invalid values are set back to a safe default (None in most cases). So its possible to call
write()afterwards even if reading data with this function failed (through this might violates the assumed consistency-model).- Parameters:
skel (SkeletonInstance) – The skeleton instance to be filled.
data (dict[str, list[str] | str]) – Dictionary from which the data is read.
amend (bool) – Defines whether content of data may be incomplete to amend the skel, which is useful for edit-actions.
ignore (Optional[Iterable[str]]) – optional list of bones to be ignored; Defaults to all readonly-bones when set to None.
- Returns:
True if all data was successfully read and complete. False otherwise (e.g. some required fields where missing or where invalid).
- Return type:
bool
- classmethod refresh(skel)¶
Refresh the bones current content.
This function causes a refresh of all relational bones and their associated information.
- Parameters:
skel (SkeletonInstance)
- classmethod readonly(skel)¶
Set all bones to readonly in the Skeleton.
- Parameters:
skel (SkeletonInstance)