skeleton

High-level database API.

class server.skeleton.BaseSkeleton(cloned=False, _cloneFrom=None, *args, **kwargs)

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.
__init__(cloned=False, _cloneFrom=None, *args, **kwargs)

Initializes a Skeleton.

Parameters:kindName (str) – If set, it overrides the kindName of the current class.
__metaclass__

alias of MetaBaseSkel

__weakref__

list of weak references to the object (if defined)

clone()

Creates a stand-alone copy of the current Skeleton object.

Returns:The stand-alone copy of the object.
Return type:Skeleton
ensureIsCloned()

Ensure that we are a instance that can be modified. If we are, just self is returned (it’s a no-op), otherwise we’ll return a cloned copy.

Returns:A copy from self or just self itself
Return type:BaseSkeleton
fromClient(data)

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
getValues()

Returns the current bones of the Skeleton as a dictionary.

Returns:Dictionary, where the keys are the bones and the values the current values.
Return type:dict
refresh()

Refresh the bones current content.

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

setBoneValue(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

setValues(values)

Load values into Skeleton, without validity checks.

This function is usually used to merge values fetched from the database into the current skeleton instance.

Warning:Performs no error-checking for invalid values! Its possible to set invalid values which may break the serialize/deserialize function of the related bone!

If no bone could be found for a given key, this key is ignored. Any values of other bones not mentioned in values remain unchanged.

Parameters:values (dict) – A dictionary with values.
classmethod subSkel(name, *args, **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
class server.skeleton.Skeleton(*args, **kwargs)

Bases: server.skeleton.BaseSkeleton

all()

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
delete()

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

fromDB(key)

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 (server.DB.Key | DB.Query | str) – 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.
Return type:bool
getSearchDocumentFields(fields)

Can be overridden to modify the list of search document fields before they are added to the index.

postDeletedHandler(key)

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

postSavedHandler(key, dbObj)

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

preProcessBlobLocks(locks)

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

preProcessSerializedData(entity)

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

toDB(clearUpdateTag=False)

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 (bool) – If True, this entity won’t be marked dirty; This avoids from being fetched by the background task updating relations.
Returns:The data store key of the entity.
Return type:str
class server.skeleton.RelSkel(cloned=False, _cloneFrom=None, *args, **kwargs)

Bases: server.skeleton.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.

fromClient(data)

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!).

@param data: Dictionary from which the data is read @type data: Dict @returns: True if the data was successfully read; False otherwise (eg. some required fields where missing or invalid)

unserialize(values)

Loads ‘values’ into this skeleton.

Parameters:values (dict | db.Entry) – Dict with values we’ll assign to our bones
Returns:
class server.skeleton.RefSkel(cloned=False, _cloneFrom=None, *args, **kwargs)

Bases: server.skeleton.RelSkel

classmethod fromSkel(skelCls, *args)

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 server.skeleton.SkelList(baseSkel)

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.
__init__(baseSkel)

@param baseSkel: The baseclass for all entries in this list

__weakref__

list of weak references to the object (if defined)