core.bones.select

Module Contents

Classes

SelectBone

A SelectBone is a bone which can take a value from a certain list of values.

Functions

translation_key_prefix_skeleton_bonename(bones_instance)

Generate a translation key prefix based on the skeleton name

translation_key_prefix_bonename(bones_instance)

Generate a translation key prefix based on the skeleton and bone name

Attributes

Self

SelectBoneValue

Type alias of possible values in a SelectBone. SelectBoneValue can be either a string (str) or a number (Number)

SelectBoneMultiple

Type alias for values of a multiple SelectBone.

core.bones.select.Self
core.bones.select.SelectBoneValue

Type alias of possible values in a SelectBone. SelectBoneValue can be either a string (str) or a number (Number)

core.bones.select.SelectBoneMultiple

Type alias for values of a multiple SelectBone.

core.bones.select.translation_key_prefix_skeleton_bonename(bones_instance)

Generate a translation key prefix based on the skeleton name

Parameters:

bones_instance (viur.core.bones.base.BaseBone) –

Return type:

str

core.bones.select.translation_key_prefix_bonename(bones_instance)

Generate a translation key prefix based on the skeleton and bone name

Parameters:

bones_instance (viur.core.bones.base.BaseBone) –

Return type:

str

class core.bones.select.SelectBone(*, defaultValue=None, values=(), translation_key_prefix='', **kwargs)

Bases: viur.core.bones.base.BaseBone

A SelectBone is a bone which can take a value from a certain list of values. Inherits from the BaseBone class. The type attribute is set to “select”.

Initializes a new SelectBone.

Parameters:
  • defaultValue (Union[SelectBoneValue, SelectBoneMultiple, Dict[str, Union[SelectBoneMultiple, SelectBoneValue]], Callable[[viur.core.skeleton.SkeletonInstance, Self], Any]]) – key(s) of the values which will be checked by default.

  • values (dict | list | tuple | Callable | enum.EnumMeta) – dict of key->value pairs from which the user can choose from – or a callable that returns a dict.

  • translation_key_prefix (str | Callable[[Self], str]) – A prefix for the key of the translation object. It is empty by default, so that only the label (dict value) from the values is used. A static string or dynamic method can be used (like translation_key_prefix_bonename).

  • kwargs – Additional keyword arguments that will be passed to the superclass’ __init__ method.

type = 'select'
__getattribute__(item)

Overrides the default __getattribute__ method to handle the ‘values’ attribute dynamically. If the ‘_values’ attribute is callable, it will be called and the result will be stored in the ‘values’ attribute.

Parameters:

item (str) – The attribute name.

Returns:

The value of the specified attribute.

Raises:

AssertionError – If the resulting values are not of type dict or OrderedDict.

singleValueUnserialize(val)

Unserializes a single value of the bone from the stored database value.

Derived bone classes should overwrite this method to implement their own logic for unserializing single values. The unserialized value should be suitable for use in the application logic.

singleValueSerialize(val, skel, name, parentIndexed)

Serializes a single value of the bone for storage in the database.

Derived bone classes should overwrite this method to implement their own logic for serializing single values. The serialized value should be suitable for storage in the database.

Parameters:
  • skel (viur.core.skeleton.SkeletonInstance) –

  • name (str) –

  • parentIndexed (bool) –

singleValueFromClient(value, skel, bone_name, client_data)

Load a single value from a client

Parameters:
  • value – The single value which should be loaded.

  • skel – The SkeletonInstance where the value should be loaded into.

  • bone_name – The bone name of this bone in the SkeletonInstance.

  • client_data – The data taken from the client, a dictionary with usually bone names as key

Returns:

A tuple. If the value is valid, the first element is the parsed value and the second is None. If the value is invalid or not parseable, the first element is a empty value and the second a list of ReadFromClientError.

structure()

Describes the bone and its settings as an JSON-serializable dict. This function has to be implemented for subsequent, specialized bone types.

Return type:

dict