core.bones.bone

Module Contents

Classes

ReadFromClientErrorSeverity

Generic enumeration.

ReadFromClientError

UniqueLockMethod

Generic enumeration.

UniqueValue

MultipleConstraints

baseBone

Functions

setSystemInitialized()

getSystemInitialized()

Attributes

__systemIsIntitialized_

core.bones.bone.__systemIsIntitialized_ = False
core.bones.bone.setSystemInitialized()
core.bones.bone.getSystemInitialized()
class core.bones.bone.ReadFromClientErrorSeverity

Bases: enum.Enum

Generic enumeration.

Derive from this class to define new enumerations.

NotSet = 0
InvalidatesOther = 1
Empty = 2
Invalid = 3
class core.bones.bone.ReadFromClientError
severity :ReadFromClientErrorSeverity
errorMessage :str
fieldPath :List[str]
invalidatedFields :List[str]
class core.bones.bone.UniqueLockMethod

Bases: enum.Enum

Generic enumeration.

Derive from this class to define new enumerations.

SameValue = 1
SameSet = 2
SameList = 3
class core.bones.bone.UniqueValue
method :UniqueLockMethod
lockEmpty :bool
message :str
class core.bones.bone.MultipleConstraints
minAmount :int = 0
maxAmount :int = 0
preventDuplicates :bool = False
class core.bones.bone.baseBone(descr='', defaultValue=None, required=False, params=None, multiple=False, indexed=True, languages=None, searchable=False, vfunc=None, readOnly=False, visible=True, unique=False, isEmptyFunc=None, getEmtpyValueFunc=None, **kwargs)

Bases: object

hasDBField = True
type = hidden
isClonedInstance = False
setSystemInitialized(self)

Can be overridden to initialize properties that depend on the Skeleton system being initialized

isInvalid(self, value)

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

isEmpty(self, rawValue: Any) bool

Check if the given single value represents the “empty” value. This usually is the empty string, 0 or False.

Warning: isEmpty takes precedence over isInvalid! The empty value is always valid - unless the bone

is required. But even then the empty value will be reflected back to the client.

Warning: rawValue might be the string/object received from the user (untrusted input!) or the value

returned by get

getDefaultValue(self, skeletonInstance)
getEmptyValue(self) Any

Returns the value representing an empty field for this bone. This might be the empty string for str/text Bones, Zero for numeric bones etc.

__setattr__(self, key, value)

Implement setattr(self, name, value).

collectRawClientData(self, name, data, multiple, languages, collectSubfields)
parseSubfieldsFromClient(self) bool

Whenever this request should try to parse subfields submitted from the client. Set only to true if you expect a list of dicts to be transmitted

singleValueFromClient(self, value, skel, name, origData)
fromClient(self, skel: SkeletonInstance, name: str, data: dict) Union[None, List[ReadFromClientError]]

Reads a value from the client. If this value is valid for this bone, store this value and return None. Otherwise our previous value is left unchanged and an error-message is returned.

Parameters
  • name (str) – Our name in the skeleton

  • data (dict) – User-supplied request-data

Returns

None or str

validateMultipleConstraints(self, skel: SkeletonInstance, name: str) List[ReadFromClientError]

Validates our value against our multiple constrains. Returns a ReadFromClientError for each violation (eg. too many items and duplicates)

singleValueSerialize(self, value, skel: SkeletonInstance, name: str, parentIndexed: bool)
serialize(self, skel: SkeletonInstance, name: str, parentIndexed: bool) bool

Serializes this bone into something we can write into the datastore.

Parameters

name (str) – The property-name this bone has in its Skeleton (not the description!)

Returns

dict

singleValueUnserialize(self, val, skel: viur.core.skeleton.SkeletonInstance, name: str)
unserialize(self, skel: viur.core.skeleton.SkeletonInstance, name: str) bool

Inverse of serialize. Evaluates whats read from the datastore and populates this bone accordingly. :param name: The property-name this bone has in its Skeleton (not the description!) :type name: str :param expando: An instance of the dictionary-like db.Entity class :type expando: db.Entity :returns: bool

delete(self, skel: viur.core.skeleton.SkeletonInstance, name: str)

Like postDeletedHandler, but runs inside the transaction

Parameters
  • skel

  • name

Returns

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

Parses the searchfilter a client specified in his Request into something understood by the datastore. This function must:

  • Ignore all filters not targeting this bone

  • Safely handle malformed data in rawFilter

    (this parameter is directly controlled by the client)

Parameters
  • name (str) – The property-name this bone has in its Skeleton (not the description!)

  • skel (server.skeleton.Skeleton) – The server.db.Query this bone is part of

  • dbFilter (server.db.Query) – The current server.db.Query instance the filters should be applied to

  • rawFilter (dict) – The dictionary of filters the client wants to have applied

Returns

The modified server.db.Query

buildDBSort(self, name, skel, dbFilter, rawFilter)

Same as buildDBFilter, but this time its not about filtering the results, but by sorting them. Again: rawFilter is controlled by the client, so you must expect and safely hande malformed data!

Parameters
  • name (str) – The property-name this bone has in its Skeleton (not the description!)

  • skel (server.skeleton.Skeleton) – The server.skeleton.Skeleton instance this bone is part of

  • dbFilter (server.db.Query) – The current server.db.Query instance the filters should be applied to

  • rawFilter (dict) – The dictionary of filters the client wants to have applied

Returns

The modified server.db.Query

_hashValueForUniquePropertyIndex(self, value: Union[str, int]) List[str]
getUniquePropertyIndexValues(self, skel, name: str) List[str]

Returns a list of hashes for our current value(s), used to store in the uniquePropertyValue index.

getReferencedBlobs(self, skel, name)

Returns the list of blob keys referenced from this bone

performMagic(self, valuesCache, name, isAdd)

This function applies “magically” functionality which f.e. inserts the current Date or the current user. :param isAdd: Signals whereever this is an add or edit operation. :type isAdd: bool

postSavedHandler(self, skel, boneName, key)

Can be overridden to perform further actions after the main entity has been written.

Parameters
  • boneName (str) – Name of this bone

  • skel (Skeleton) – The skeleton this bone belongs to

  • key (str) – The (new?) Database Key we’ve written to

  • dbObj (db.Entity) – The db.Entity object written

postDeletedHandler(self, skel, boneName, key)

Can be overridden to perform further actions after the main entity has been deleted.

Parameters
  • skel (Skeleton) – The skeleton this bone belongs to

  • boneName (str) – Name of this bone

  • key (str) – The old Database Key of the entity we’ve deleted

refresh(self, skel, boneName) None

Refresh all values we might have cached from other entities.

mergeFrom(self, valuesCache, boneName, otherSkel)

Clones the values from other into this instance

setBoneValue(self, skel: SkeletonInstance, boneName: str, value: Any, append: bool, language: Union[None, str] = None) bool

Set our value to ‘value’. Santy-Checks are performed; if the value is invalid, no modification will happen.

Parameters
  • skel – Dictionary with the current values from the skeleton we belong to

  • boneName – The Bone which should be modified

  • value – The value that should be assigned. It’s type depends on the type of that bone

  • append – If true, the given value is appended to the values of that bone instead of replacing it. Only supported on bones with multiple=True

  • language – Set/append which language

Returns

Wherever that operation succeeded or not.

getSearchTags(self, skeletonInstance, name: str) Set[str]