core.bones.string

Module Contents

Classes

StringBone

The "StringBone" represents a data field that contains text values.

Attributes

DB_TYPE_INDEXED

core.bones.string.DB_TYPE_INDEXED: TypeAlias
class core.bones.string.StringBone(*, caseSensitive=True, max_length=254, min_length=None, natural_sorting=False, **kwargs)

Bases: viur.core.bones.base.BaseBone

The “StringBone” represents a data field that contains text values.

Initializes a new StringBone.

Parameters:
  • caseSensitive (bool) – When filtering for values in this bone, should it be case-sensitive?

  • max_length (int | None) – The maximum length allowed for values of this bone. Set to None for no limitation.

  • min_length (int | None) – The minimum length allowed for values of this bone. Set to None for no limitation.

  • natural_sorting (bool | Callable) – Allows a more natural sorting than the default sorting on the plain values. This uses the .sort_idx property. True enables sorting according to DIN 5007 Variant 2. With passing a callable, a custom transformer method can be set that creates the value for the index property.

  • kwargs – Inherited arguments from the BaseBone.

type = 'str'
type_coerce_single_value(value)

Convert a value to a string (if not already)

Converts a value that is not a string into a string if a meaningful conversion is possible (simple data types only).

Parameters:

value (Any) –

Return type:

str

singleValueSerialize(value, skel, name, parentIndexed)

Serializes a single value of this data field for storage in the database.

Parameters:
  • value (Any) – The value to serialize. It should be a str value, if not it is forced with type_coerce_single_value().

  • skel (core.skeleton.SkeletonInstance) – The skeleton instance that this data field belongs to.

  • name (str) – The name of this data field.

  • parentIndexed (bool) – A boolean value indicating whether the parent object has an index on this data field or not.

Returns:

The serialized value.

Return type:

str | DB_TYPE_INDEXED

singleValueUnserialize(value)

Unserializes a single value of this data field from the database.

Parameters:

value (str | DB_TYPE_INDEXED) – The serialized value to unserialize.

Returns:

The unserialized value.

Return type:

str

getEmptyValue()

Returns the empty value for this data field.

Returns:

An empty string.

Return type:

str

isEmpty(value)

Determines whether a value for this data field is empty or not.

Parameters:

value – The value to check for emptiness.

Returns:

A boolean value indicating whether the value is empty or not.

isInvalid(value)

Returns None if the value would be valid for this bone, an error-message otherwise.

Parameters:

value (Any) –

Return type:

str | None

singleValueFromClient(value, skel, bone_name, client_data)

Returns None and the escaped value if the value would be valid for this bone, otherwise the empty value and an error-message.

buildDBFilter(name, skel, dbFilter, rawFilter, prefix=None)

Builds and returns a database filter for this data field based on the provided raw filter data.

Parameters:
  • name (str) – The name of this data field.

  • skel (core.skeleton.SkeletonInstance) – The skeleton instance that this data field belongs to.

  • dbFilter (viur.core.db.Query) – The database filter to add query clauses to.

  • rawFilter (dict) – A dictionary containing the raw filter data for this data field.

  • prefix (Optional[str]) – An optional prefix to add to the query clause.

Returns:

The database filter with the added query clauses.

Return type:

viur.core.db.Query

buildDBSort(name, skel, dbFilter, rawFilter)

Build a DB sort based on the specified name and a raw filter.

Parameters:
  • name (str) – The name of the attribute to sort by.

  • skel (core.skeleton.SkeletonInstance) – A SkeletonInstance object.

  • dbFilter (viur.core.db.Query) – A Query object representing the current DB filter.

  • rawFilter (dict) – A dictionary containing the raw filter.

Returns:

The Query object with the specified sort applied.

Return type:

Optional[viur.core.db.Query]

natural_sorting(value)

Implements a default natural sorting transformer.

The sorting is according to DIN 5007 Variant 2 and sets ö and oe, etc. equal.

Parameters:

value (str | None) –

Return type:

str | None

getSearchTags(skel, name)

Returns a set of lowercased words that represent searchable tags for the given bone.

Parameters:
Returns:

A set of lowercased words representing searchable tags.

Return type:

set[str]

getUniquePropertyIndexValues(skel, name)

Returns a list of unique index values for a given property name.

Parameters:
Returns:

A list of unique index values for the property.

Raises:

NotImplementedError – If the StringBone has languages and the implementation for this case is not yet defined.

Return type:

list[str]

refresh(skel, bone_name)

Refresh all values we might have cached from other entities.

Parameters:
Return type:

None

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