core.skeleton

Module Contents

Classes

MetaBaseSkel

This is the meta class for Skeletons.

SkeletonInstance

The actual wrapper around a Skeleton-Class. An object of this class is what's actually returned when you

BaseSkeleton

This is a container-object holding information about one database entity.

MetaSkel

This is the meta class for Skeletons.

CustomDatabaseAdapter

ViurTagsSearchAdapter

This Adapter implements the a simple fulltext search ontop of the datastore.

seoKeyBone

Skeleton

This is a container-object holding information about one database entity.

RelSkel

This is a Skeleton-like class that acts as a container for Skeletons used as a

RefSkel

This is a Skeleton-like class that acts as a container for Skeletons used as a

SkelList

This class is used to hold multiple skeletons together with other, commonly used information.

TaskUpdateSearchIndex

This tasks loads and saves every entity of the given module.

RebuildSearchIndex

TaskVacuumRelations

Checks entries in viur-relations and verifies that the src-kind and it's relational-bone still exists.

Functions

skeletonByKind(kindName: str) → Skeleton

Returns the Skeleton-Class for the given kindName. That skeleton must exist, otherwise an exception is raised.

listKnownSkeletons() → List[str]

return

A list of all known kindnames (all kindnames for which a skeleton is defined)

iterAllSkelClasses() → Iterable[Skeleton]

return

An iterator that yields each Skeleton-Class once. (Only top-level skeletons are returned, so no

processRemovedRelations(removedKey, cursor=None)

updateRelations(destID, minChangeTime, changeList, cursor=None)

processVacuumRelationsChunk(module, cursor, allCount=0, removedCount=0, notify=None)

Processes 100 Entries and calls the next batch

Attributes

pytz

__undefindedC__

SkeletonInstanceRef

SkelListRef

core.skeleton.pytz
core.skeleton.__undefindedC__
class core.skeleton.MetaBaseSkel(cls, name, bases, dct)

Bases: type

This is the meta class for Skeletons. It is used to enforce several restrictions on bone names, etc.

_skelCache
_allSkelClasses
__reservedKeywords_
core.skeleton.skeletonByKind(kindName: str) Skeleton

Returns the Skeleton-Class for the given kindName. That skeleton must exist, otherwise an exception is raised. :param kindName: The kindname to retreive the skeleton for :return: The skeleton-class for that kind

core.skeleton.listKnownSkeletons() List[str]
Returns

A list of all known kindnames (all kindnames for which a skeleton is defined)

core.skeleton.iterAllSkelClasses() Iterable[Skeleton]
Returns

An iterator that yields each Skeleton-Class once. (Only top-level skeletons are returned, so no RefSkel classes will be included)

class core.skeleton.SkeletonInstance(skelCls, subSkelNames=None, fullClone=False, clonedBoneMap=None)

The actual wrapper around a Skeleton-Class. An object of this class is what’s actually returned when you call a Skeleton-Class. With ViUR3, you don’t get an instance of a Skeleton-Class any more - it’s always this class. This is much faster as this is a small class.

__slots__
items(self, yieldBoneValues: bool = False) Iterable[Tuple[str, viur.core.bones.baseBone]]
keys(self) Iterable[str]
values(self) Iterable[Any]
__iter__(self) Iterable[str]
__contains__(self, item)
__setitem__(self, key, value)
__getitem__(self, key)
__getattr__(self, item)
__delattr__(self, item)

Implement delattr(self, name).

__setattr__(self, key, value)

Implement setattr(self, name, value).

__repr__(self) str

Return repr(self).

clone(self)
setEntity(self, entity: viur.core.db.Entity)
__deepcopy__(self, memodict)
class core.skeleton.BaseSkeleton

Bases: object

This is a container-object holding information about one database entity.

It has to be sub-classed with individual information about the kindName of the entities and its specific data attributes, the so called bones. The Skeleton stores its bones in an OrderedDict-Instance, so the definition order of the contained bones remains constant.

Variables
  • key (server.bones.baseBone) – This bone stores the current database key of this entity. Assigning to this bones value is dangerous and does not affect the actual key its stored in.

  • creationdate (server.bones.dateBone) – The date and time where this entity has been created.

  • changedate (server.bones.dateBone) – The date and time of the last change to this entity.

__viurBaseSkeletonMarker__ = True
boneMap
classmethod subSkel(cls, *args, fullClone=False, **kwargs)

Creates a new sub-skeleton as part of the current skeleton.

A sub-skeleton is a copy of the original skeleton, containing only a subset of its bones. To define sub-skeletons, use the subSkels property of the Skeleton object.

By passing multiple sub-skeleton names to this function, a sub-skeleton with the union of all bones of the specified sub-skeletons is returned.

If an entry called “*” exists in the subSkels-dictionary, the bones listed in this entry will always be part of the generated sub-skeleton.

Parameters

name (str) – Name of the sub-skeleton (that’s the key of the subSkels dictionary); Multiple names can be specified.

Returns

The sub-skeleton of the specified type.

Return type

server.skeleton.Skeleton

classmethod setSystemInitialized(cls)
classmethod setBoneValue(cls, skelValues, boneName, value, append=False)

Allow setting a bones value without calling fromClient or assigning to valuesCache directly. Santy-Checks are performed; if the value is invalid, that bone flips back to its original (default) value and false is returned.

Parameters
  • boneName (str) – The Bone which should be modified

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

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

Returns

Wherever that operation succeeded or not.

Return type

bool

classmethod fromClient(cls, skelValues: SkeletonInstance, data: Dict[str, Union[List[str], str]], allowEmptyRequired=False) bool

Load supplied data into Skeleton.

This function works similar to setValues(), except that the values retrieved from data are checked against the bones and their validity checks.

Even if this function returns False, all bones are guaranteed to be in a valid state. The ones which have been read correctly are set to their valid values; Bones with invalid values are set back to a safe default (None in most cases). So its possible to call toDB() afterwards even if reading data with this function failed (through this might violates the assumed consistency-model).

Parameters

data (dict) – Dictionary from which the data is read.

Returns

True if all data was successfully read and taken by the Skeleton’s bones. False otherwise (eg. some required fields where missing or invalid).

Return type

bool

classmethod refresh(cls, skelValues)

Refresh the bones current content.

This function causes a refresh of all relational bones and their associated information.

class core.skeleton.MetaSkel(cls, name, bases, dct)

Bases: MetaBaseSkel

This is the meta class for Skeletons. It is used to enforce several restrictions on bone names, etc.

class core.skeleton.CustomDatabaseAdapter
providesFulltextSearch :bool = False
fulltextSearchGuaranteesQueryConstrains = False
providesCustomQueries :bool = False
preprocessEntry(self, entry: viur.core.db.Entity, skel: BaseSkeleton, changeList: List[str], isAdd: bool) viur.core.db.Entity

Can be overridden to add or alter the data of this entry before it’s written to firestore. Will always be called inside an transaction. :param entry: The entry containing the serialized data of that skeleton :param skel: The (complete) skeleton this skel.toDB() runs for :param changeList: List of boneNames that are changed by this skel.toDB() call :param isAdd: Is this an update or an add? :return: The (maybe modified) entity

updateEntry(self, dbObj: viur.core.db.Entity, skel: BaseSkeleton, changeList: List[str], isAdd: bool) None

Like meth:preprocessEntry, but runs after the transaction had completed. Changes made to dbObj will be ignored. :param entry: The entry containing the serialized data of that skeleton :param skel: The (complete) skeleton this skel.toDB() runs for :param changeList: List of boneNames that are changed by this skel.toDB() call :param isAdd: Is this an update or an add?

deleteEntry(self, entry: viur.core.db.Entity, skel: BaseSkeleton) None

Called, after an skeleton has been successfully deleted from firestore :param entry: The db.Entity object containing an snapshot of the data that has been deleted :param skel: The (complete) skeleton for which `meth:delete’ had been called

abstract fulltextSearch(self, queryString: str, databaseQuery: viur.core.db.Query) List[viur.core.db.Entity]

If this database supports fulltext searches, this method has to implement them. If it’s a plain fulltext search engine, leave ‘prop:fulltextSearchGuaranteesQueryConstrains’ set to False, then the server will post-process the list of entries returned from this function and drop any entry that cannot be returned due to other constrains set in ‘param:databaseQuery’. If you can obey every constrain set in that Query, we can skip this post-processing and save some CPU-cycles. :param queryString: the string as received from the user (no quotation or other safety checks applied!) :param databaseQuery: The query containing any constrains that returned entries must also match :return:

class core.skeleton.ViurTagsSearchAdapter(minLength: int = 3)

Bases: CustomDatabaseAdapter

This Adapter implements the a simple fulltext search ontop of the datastore. On skel.toDB we collect all words from str/textBones, build all minLength postfixes and dump them into the property viurTags. When queried, we’ll run a prefix-match against this property - thus returning entities with either a exact match or a match inside a word.

Example:

For the word “hello” we’ll write “hello”, “ello” and “llo” into viurTags. When queried with “hello” we’ll have an exact match. When queried with “hel” we’ll match the prefix for “hello” When queried with “ell” we’ll prefix-match “ello”

We’ll automatically add this adapter if a skeleton has no other database adapter defined

providesFulltextSearch = True
fulltextSearchGuaranteesQueryConstrains = True
_tagsFromString(self, value: str) Set[str]

Extract all words including all minLength postfixes from given string

preprocessEntry(self, entry: viur.core.db.Entity, skel: Skeleton, changeList: List[str], isAdd: bool) viur.core.db.Entity

Collect searchTags from skeleton and build viurTags

fulltextSearch(self, queryString: str, databaseQuery: viur.core.db.Query) List[viur.core.db.Entity]

Run a fulltext search

class core.skeleton.seoKeyBone

Bases: viur.core.bones.stringBone

unserialize(self, skel: viur.core.skeleton.SkeletonInstance, name: str) bool
class core.skeleton.Skeleton(*args, **kwargs)

Bases: BaseSkeleton

This is a container-object holding information about one database entity.

It has to be sub-classed with individual information about the kindName of the entities and its specific data attributes, the so called bones. The Skeleton stores its bones in an OrderedDict-Instance, so the definition order of the contained bones remains constant.

Variables
  • key (server.bones.baseBone) – This bone stores the current database key of this entity. Assigning to this bones value is dangerous and does not affect the actual key its stored in.

  • creationdate (server.bones.dateBone) – The date and time where this entity has been created.

  • changedate (server.bones.dateBone) – The date and time of the last change to this entity.

kindName :str
customDatabaseAdapter :Union[CustomDatabaseAdapter, None]
subSkels
interBoneValidations :List[Callable[[Skeleton], List[viur.core.bones.bone.ReadFromClientError]]] = []
key
creationdate
changedate
viurCurrentSeoKeys
__repr__(self)

Return repr(self).

classmethod all(cls, skelValues, **kwargs)

Create a query with the current Skeletons kindName.

Returns

A db.Query object which allows for entity filtering and sorting.

Return type

server.db.Query

classmethod fromClient(cls, skelValues: SkeletonInstance, data: Dict[str, Union[List[str], str]], allowEmptyRequired=False) bool

This function works similar to setValues(), except that the values retrieved from data are checked against the bones and their validity checks.

Even if this function returns False, all bones are guaranteed to be in a valid state. The ones which have been read correctly are set to their valid values; Bones with invalid values are set back to a safe default (None in most cases). So its possible to call toDB() afterwards even if reading data with this function failed (through this might violates the assumed consistency-model).

Parameters

data – Dictionary from which the data is read.

Returns

True, if all values have been read correctly (without errors), False otherwise

classmethod fromDB(cls, skelValues: SkeletonInstance, key: Union[str, viur.core.db.KeyClass]) bool

Load entity with key from the data store into the Skeleton.

Reads all available data of entity kind kindName and the key key from the data store into the Skeleton structure’s bones. Any previous data of the bones will discard.

To store a Skeleton object to the data store, see toDB().

Parameters

key – A server.DB.Key, server.DB.Query, or string, from which the data shall be fetched.

Returns

True on success; False if the given key could not be found.

classmethod toDB(cls, skelValues: SkeletonInstance, clearUpdateTag: bool = False) viur.core.db.KeyClass

Store current Skeleton entity to data store.

Stores the current data of this instance into the database. If an key value is set to the object, this entity will ne updated; Otherwise an new entity will be created.

To read a Skeleton object from the data store, see fromDB().

Parameters

clearUpdateTag – If True, this entity won’t be marked dirty; This avoids from being fetched by the background task updating relations.

Returns

The datastore key of the entity.

classmethod preProcessBlobLocks(cls, skelValues, locks)

Can be overridden to modify the list of blobs referenced by this skeleton

classmethod preProcessSerializedData(cls, skelValues, entity)

Can be overridden to modify the server.db.Entity before its actually written to the data store.

classmethod postSavedHandler(cls, skelValues, key, dbObj)

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

classmethod postDeletedHandler(cls, skelValues, key)

Can be overridden to perform further actions after the entity has been deleted from the data store.

classmethod getCurrentSEOKeys(cls, skelValues) Union[None, Dict[str, str]]

Should be overridden to return a dictionary of language -> SEO-Friendly key this entry should be reachable under. How theses names are derived are entirely up to the application. If the name is already in use for this module, the server will automatically append some random string to make it unique. :return:

classmethod delete(cls, skelValues)

Deletes the entity associated with the current Skeleton from the data store.

class core.skeleton.RelSkel

Bases: BaseSkeleton

This is a Skeleton-like class that acts as a container for Skeletons used as a additional information data skeleton for extendedRelationalBone.

It needs to be sub-classed where information about the kindName and its attributes (bones) are specified.

The Skeleton stores its bones in an OrderedDict-Instance, so the definition order of the contained bones remains constant.

classmethod fromClient(cls, skelValues: SkeletonInstance, data: Dict[str, Union[List[str], str]], allowEmptyRequired=False) bool

Reads the data supplied by data. Unlike setValues, error-checking is performed. The values might be in a different representation than the one used in getValues/serValues. Even if this function returns False, all bones are guranteed to be in a valid state: The ones which have been read correctly contain their data; the other ones are set back to a safe default (None in most cases) So its possible to call save() afterwards even if reading data fromClient faild (through this might violates the assumed consitency-model!).

Parameters

data (dict) – Dictionary from which the data is read

Returns

True if the data was successfully read; False otherwise (eg. some required fields where missing or invalid)

serialize(self, parentIndexed)
unserialize(self, values)

Loads ‘values’ into this skeleton.

Parameters

values (dict | db.Entry) – dict with values we’ll assign to our bones

Returns

class core.skeleton.RefSkel

Bases: RelSkel

This is a Skeleton-like class that acts as a container for Skeletons used as a additional information data skeleton for extendedRelationalBone.

It needs to be sub-classed where information about the kindName and its attributes (bones) are specified.

The Skeleton stores its bones in an OrderedDict-Instance, so the definition order of the contained bones remains constant.

classmethod fromSkel(cls, kindName: str, *args: List[str])

Creates a relSkel from a skeleton-class using only the bones explicitly named in *args

Parameters
  • skelCls (BaseSkeleton) – A class or instance of BaseSkel we’ll adapt the model from

  • args (list of str) – List of bone names we’ll adapt

Returns

A new instance of RefSkel

Return type

RefSkel

class core.skeleton.SkelList(baseSkel=None)

Bases: list

This class is used to hold multiple skeletons together with other, commonly used information.

SkelLists are returned by Skel().all()…fetch()-constructs and provide additional information about the data base query, for fetching additional entries.

Variables

cursor (str) – Holds the cursor within a query.

__slots__ = ['baseSkel', 'getCursor', 'customQueryInfo', 'renderPreparation']
core.skeleton.processRemovedRelations(removedKey, cursor=None)
core.skeleton.updateRelations(destID, minChangeTime, changeList, cursor=None)
class core.skeleton.TaskUpdateSearchIndex

Bases: viur.core.tasks.CallableTaskBase

This tasks loads and saves every entity of the given module. This ensures an updated searchIndex and verifies consistency of this data.

key = rebuildSearchIndex
name = Rebuild search index
descr = This task can be called to update search indexes and relational information.
canCall(self) bool

Checks wherever the current user can execute this task

dataSkel(self)
execute(self, module, *args, **kwargs)
static _run(module: str, notify: str)
class core.skeleton.RebuildSearchIndex

Bases: viur.core.tasks.QueryIter

classmethod handleEntry(cls, skel: SkeletonInstance, customData: Dict[str, str])
classmethod handleFinish(cls, totalCount: int, customData: Dict[str, str])
class core.skeleton.TaskVacuumRelations

Bases: viur.core.tasks.CallableTaskBase

Checks entries in viur-relations and verifies that the src-kind and it’s relational-bone still exists.

key = vacuumRelations
name = Vacuum viur-relations (dangerous)
descr = Drop stale inbound relations for the given kind
canCall(self)

Checks wherever the current user can execute this task :returns: bool

dataSkel(self)
execute(self, module, *args, **kwargs)
core.skeleton.processVacuumRelationsChunk(module, cursor, allCount=0, removedCount=0, notify=None)

Processes 100 Entries and calls the next batch

core.skeleton.SkeletonInstanceRef
core.skeleton.SkelListRef