core.bones.record

Module Contents

Classes

RecordBone

The RecordBone class is a specialized bone type used to store structured data. It inherits from

class core.bones.record.RecordBone(*, format=None, indexed=False, using=None, **kwargs)

Bases: viur.core.bones.base.BaseBone

The RecordBone class is a specialized bone type used to store structured data. It inherits from the BaseBone class. The RecordBone class is designed to store complex data structures, such as nested dictionaries or objects, by using a related skeleton class (the using parameter) to manage the internal structure of the data.

Parameters:
  • format (str) – Optional string parameter to specify the format of the record bone.

  • indexed (bool) – Optional boolean parameter to indicate if the record bone is indexed. Defaults to False.

  • using (viur.core.skeleton.RelSkel) – A class that inherits from ‘viur.core.skeleton.RelSkel’ to be used with the RecordBone.

  • kwargs – Additional keyword arguments to be passed to the BaseBone constructor.

Initializes a new Bone.

type = 'record'
singleValueUnserialize(val)

Unserializes a single value, creating an instance of the ‘using’ class and unserializing the value into it.

Parameters:

val – The value to unserialize.

Returns:

An instance of the ‘using’ class with the unserialized data.

Raises:

AssertionError – If the unserialized value is not a dictionary.

singleValueSerialize(value, skel, name, parentIndexed)

Serializes a single value by calling the serialize method of the ‘using’ skeleton instance.

Parameters:
  • value – The value to be serialized, which should be an instance of the ‘using’ skeleton.

  • skel (SkeletonInstance) – The parent skeleton instance.

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

  • parentIndexed (bool) – A boolean indicating if the parent bone is indexed.

Returns:

The serialized value.

parseSubfieldsFromClient()

Determines if the current request should attempt to parse subfields received from the client. This should only be set to True if a list of dictionaries is expected to be transmitted.

Return 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.

getSearchTags(skel, name)

Collects search tags from the ‘using’ skeleton instance for the given bone.

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

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

Returns:

A set of search tags generated from the ‘using’ skeleton instance.

Return type:

set[str]

getSearchDocumentFields(valuesCache, name, prefix='')

Generates a list of search document fields for the given values cache, name, and optional prefix.

Parameters:
  • valuesCache (dict) – A dictionary containing the cached values.

  • name (str) – The name of the bone to process.

  • prefix (str) – An optional prefix to use for the search document fields, defaults to an empty string.

Returns:

A list of search document fields.

Return type:

list

getReferencedBlobs(skel, name)

Retrieves a set of referenced blobs for the given skeleton instance and name.

Parameters:
  • skel (SkeletonInstance) – The skeleton instance to process.

  • name (str) – The name of the bone to process.

Returns:

A set of referenced blobs.

Return type:

set[str]

abstract getUniquePropertyIndexValues(valuesCache, name)

This method is intentionally not implemented as it’s not possible to determine how to derive a key from the related skeleton being used (i.e., which fields to include and how).

Parameters:
  • valuesCache (dict) –

  • name (str) –

Return type:

list[str]

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