core.bones.string

Module Contents

Classes

StringBone

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

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'
singleValueSerialize(value, skel, name, parentIndexed)

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

Parameters:
  • value – The value to serialize.

  • skel (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.

singleValueUnserialize(value)

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

Parameters:

value – The serialized value to unserialize.

Returns:

The unserialized value.

getEmptyValue()

Returns the empty value for this data field.

Returns:

An empty string.

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.

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 (viur.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 (viur.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[google.cloud.ndb.query.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:
  • skel (viur.core.skeleton.SkeletonInstance) – The skeleton instance being searched.

  • name (str) – The name of the bone to generate tags for.

Returns:

A set of lowercased words representing searchable tags.

Return type:

set

getUniquePropertyIndexValues(skel, name)

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

Parameters:
  • skel – The skeleton instance.

  • name (str) – The name of the property.

Returns:

A list of unique index values for the property.

Return type:

List[str]

Raises:

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

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