core.skeleton.meta ================== .. py:module:: core.skeleton.meta Attributes ---------- .. autoapisummary:: core.skeleton.meta._UNDEFINED_KINDNAME core.skeleton.meta.ABSTRACT_SKEL_CLS_SUFFIX Classes ------- .. autoapisummary:: core.skeleton.meta.MetaBaseSkel core.skeleton.meta.MetaSkel core.skeleton.meta.BaseSkeleton Module Contents --------------- .. py:data:: _UNDEFINED_KINDNAME .. py:data:: ABSTRACT_SKEL_CLS_SUFFIX :value: 'AbstractSkel' .. py:class:: MetaBaseSkel(name, bases, dct, **kwargs) Bases: :py:obj:`type` This is the metaclass for Skeletons. It is used to enforce several restrictions on bone names, etc. .. py:attribute:: _skelCache .. py:attribute:: _allSkelClasses .. py:attribute:: __reserved_keywords .. py:attribute:: __allowed_chars :value: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_' .. py:method:: generate_bonemap(cls) :staticmethod: Recursively constructs a dict of bones from .. py:method:: __setattr__(key, value) .. py:class:: MetaSkel(name, bases, dct, **kwargs) Bases: :py:obj:`MetaBaseSkel` This is the metaclass for Skeletons. It is used to enforce several restrictions on bone names, etc. .. py:class:: BaseSkeleton Bases: :py:obj:`object` This 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 :class:`OrderedDict`-Instance, so the definition order of the contained bones remains constant. :ivar key: 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. :vartype key: server.bones.BaseBone :ivar creationdate: The date and time where this entity has been created. :vartype creationdate: server.bones.DateBone :ivar changedate: The date and time of the last change to this entity. :vartype changedate: server.bones.DateBone .. py:attribute:: __viurBaseSkeletonMarker__ :value: True .. py:attribute:: boneMap :value: None .. py:method:: subSkel(*subskel_names, fullClone = False, **kwargs) :classmethod: .. py:method:: subskel(*names, bones = (), clone = False) :classmethod: 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. 1. 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. 2. 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. 3. Both modes (1 + 2) can be combined, but then the original order of the bones is kept. 4. The "key" bone is automatically available in each sub-skeleton. 5. 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 ``` :param bones: 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. :param clone: If set True, performs a cloning of the used bone map, to be entirely stand-alone. :return: The sub-skeleton of the specified type. .. py:method:: setSystemInitialized() :classmethod: .. py:method:: setBoneValue(skel, boneName, value, append = False, language = None) :classmethod: 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. :param boneName: The name of the bone to be modified :param value: The value that should be assigned. It's type depends on the type of that bone :param append: If True, the given value is appended to the values of that bone instead of replacing it. Only supported on bones with multiple=True :param language: Language to set :return: Wherever that operation succeeded or not. .. py:method:: fromClient(skel, data, *, amend = False, ignore = None) :classmethod: Load supplied *data* into Skeleton. This function works similar to :func:`~viur.core.skeleton.Skeleton.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 :func:`~viur.core.skeleton.Skeleton.write` afterwards even if reading data with this function failed (through this might violates the assumed consistency-model). :param skel: The skeleton instance to be filled. :param data: Dictionary from which the data is read. :param amend: Defines whether content of data may be incomplete to amend the skel, which is useful for edit-actions. :param ignore: 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). .. py:method:: refresh(skel) :classmethod: Refresh the bones current content. This function causes a refresh of all relational bones and their associated information. .. py:method:: readonly(skel) :classmethod: Set all bones to readonly in the Skeleton.