core.bones.base
¶
Module Contents¶
Classes¶
Generic enumeration. |
|
Generic enumeration. |
|
Functions¶
Attributes¶
- core.bones.base.__systemIsIntitialized_ = False¶
- core.bones.base.setSystemInitialized()¶
- core.bones.base.getSystemInitialized()¶
- class core.bones.base.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.base.ReadFromClientError¶
- severity :ReadFromClientErrorSeverity¶
- errorMessage :str¶
- fieldPath :List[str]¶
- invalidatedFields :List[str]¶
- class core.bones.base.UniqueLockMethod¶
Bases:
enum.Enum
Generic enumeration.
Derive from this class to define new enumerations.
- SameValue = 1¶
- SameSet = 2¶
- SameList = 3¶
- class core.bones.base.MultipleConstraints¶
- minAmount :int = 0¶
- maxAmount :int = 0¶
- preventDuplicates :bool = False¶
- class core.bones.base.BaseBone(*, defaultValue: Any = None, descr: str = '', getEmptyValueFunc: callable = None, indexed: bool = True, isEmptyFunc: callable = None, languages: Union[None, List[str]] = None, multiple: Union[bool, MultipleConstraints] = False, params: Dict = None, readOnly: bool = False, required: bool = False, searchable: bool = False, unique: Union[None, UniqueValue] = None, vfunc: callable = None, visible: bool = True)¶
Bases:
object
- type = hidden¶
- isClonedInstance = False¶
- setSystemInitialized()¶
Can be overridden to initialize properties that depend on the Skeleton system being initialized
- isInvalid(value)¶
Returns None if the value would be valid for this bone, an error-message otherwise.
- isEmpty(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(skeletonInstance)¶
- getEmptyValue() 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__(key, value)¶
Implement setattr(self, name, value).
- collectRawClientData(name, data, multiple, languages, collectSubfields)¶
- parseSubfieldsFromClient() 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(value, skel, name, origData)¶
- fromClient(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
skel – The skeleton instance where the values should be loaded.
name – Our name in the skeleton
data – User-supplied request-data
- Returns
None or a list of errors
- validateMultipleConstraints(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(value, skel: SkeletonInstance, name: str, parentIndexed: bool)¶
- serialize(skel: SkeletonInstance, name: str, parentIndexed: bool) bool ¶
Serializes this bone into something we can write into the datastore.
- Parameters
name – The property-name this bone has in its Skeleton (not the description!)
- singleValueUnserialize(val)¶
- unserialize(skel: viur.core.skeleton.SkeletonInstance, name: str) bool ¶
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!)
- delete(skel: viur.core.skeleton.SkeletonInstance, name: str)¶
Like postDeletedHandler, but runs inside the transaction
- buildDBFilter(name: str, skel: viur.core.skeleton.SkeletonInstance, dbFilter: viur.core.db.Query, rawFilter: Dict, prefix: Optional[str] = None) viur.core.db.Query ¶
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 – The property-name this bone has in its Skeleton (not the description!)
skel – The
viur.core.db.Query
this bone is part ofdbFilter – The current
viur.core.db.Query
instance the filters should be applied torawFilter – The dictionary of filters the client wants to have applied
- Returns
The modified
viur.core.db.Query
- buildDBSort(name: str, skel: viur.core.skeleton.SkeletonInstance, dbFilter: viur.core.db.Query, rawFilter: Dict) Optional[viur.core.db.Query] ¶
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 – The property-name this bone has in its Skeleton (not the description!)
skel – The
viur.core.skeleton.Skeleton
instance this bone is part ofdbFilter – The current
viur.core.db.Query
instance the filters should be applied torawFilter – The dictionary of filters the client wants to have applied
- Returns
The modified
viur.core.db.Query
, None if the query is unsatisfiable.
- getUniquePropertyIndexValues(skel: viur.core.skeleton.SkeletonInstance, name: str) List[str] ¶
Returns a list of hashes for our current value(s), used to store in the uniquePropertyValue index.
- getReferencedBlobs(skel: viur.core.skeleton.SkeletonInstance, name: str)¶
Returns the list of blob keys referenced from this bone
- performMagic(valuesCache: Dict, name: str, isAdd: bool)¶
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.
- postSavedHandler(skel: viur.core.skeleton.SkeletonInstance, boneName: str, key: str)¶
Can be overridden to perform further actions after the main entity has been written.
- Parameters
boneName – Name of this bone
skel – The skeleton this bone belongs to
key – The (new?) Database Key we’ve written to
- postDeletedHandler(skel: viur.core.skeleton.SkeletonInstance, boneName: str, key: str)¶
Can be overridden to perform further actions after the main entity has been deleted.
- Parameters
skel – The skeleton this bone belongs to
boneName – Name of this bone
key – The old Database Key of the entity we’ve deleted
- refresh(skel: viur.core.skeleton.SkeletonInstance, boneName: str) None ¶
Refresh all values we might have cached from other entities.
- mergeFrom(valuesCache: Dict, boneName: str, otherSkel: viur.core.skeleton.SkeletonInstance)¶
Clones the values from other into this instance
- setBoneValue(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(skeletonInstance, name: str) Set[str] ¶