core.bones.boolean
¶
Module Contents¶
Classes¶
Represents a boolean data type, which can have two possible values: True or False. |
Attributes¶
- core.bones.boolean.DEFAULT_VALUE_T: TypeAlias¶
- class core.bones.boolean.BooleanBone(*, defaultValue=None, **kwargs)¶
Bases:
viur.core.bones.base.BaseBone
Represents a boolean data type, which can have two possible values: True or False. It also allows for None to specify the “not yet set”-state. BooleanBones cannot be defined as multiple=True.
- Parameters:
defaultValue (DEFAULT_VALUE_T | Callable[[Self, SkeletonInstance], DEFAULT_VALUE_T]) – The default value of the BooleanBone instance. Defaults to None (unset).
- Raises:
ValueError – If the defaultValue is not either a boolean value (True or False) or None.
Initializes a new Bone.
- type = '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.
- getEmptyValue()¶
Returns the empty value of the BooleanBone class, which is False.
- Returns:
The empty value of the BooleanBone class (False).
- Return type:
bool
- isEmpty(value)¶
Checks if the given boolean value is empty.
- Parameters:
value (Any) – The boolean value to be checked.
- Returns:
True if the boolean value is empty (i.e., equal to the empty value of the BooleanBone class), False otherwise.
- Return type:
bool
- refresh(skel, boneName)¶
Inverse of serialize. Evaluates whats read from the datastore and populates this bone accordingly.
- Parameters:
name – The property-name this bone has in its Skeleton (not the description!)
skel (viur.core.skeleton.SkeletonInstance) –
boneName (str) –
- Return type:
None
- setBoneValue(skel, boneName, value, append, language=None)¶
Sets the value of the bone to the provided ‘value’. Sanity checks are performed; if the value is invalid, the bone value will revert to its original (default) value and the function will return False.
- Parameters:
skel (SkeletonInstance) – Dictionary with the current values from the skeleton the bone belongs to
boneName (str) – The name of the bone that should be modified
value (Any) – The value that should be assigned. Its type depends on the type of the bone
append (bool) – If True, the given value will be appended to the existing bone values instead of replacing them. Only supported on bones with multiple=True
language (None | str) – Optional, the language of the value if the bone is language-aware
- Returns:
A boolean indicating whether the operation succeeded or not
- Return type:
bool
- singleValueSerialize(value, 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 (SkeletonInstance) –
name (str) –
parentIndexed (bool) –
- buildDBFilter(name, skel, dbFilter, rawFilter, prefix=None)¶
Builds a database filter based on the boolean value.
- Parameters:
name (str) – The name of the BooleanBone instance.
skel (viur.core.skeleton.SkeletonInstance) – The SkeletonInstance object representing the data of the current entity.
dbFilter (viur.core.db.Query) – The Query object representing the current database filter.
rawFilter (dict) – The dictionary representing the raw filter data received from the client.
prefix (Optional[str]) – A prefix to be added to the property name in the database filter.
- Returns:
The updated Query object representing the updated database filter.
- Return type:
google.cloud.ndb.query.Query