bones

baseBone

The base-class for all bones. If you implement your own bones you must also subclass from this one.

class server.bones.bone.baseBone(descr='', defaultValue=None, required=False, params=None, multiple=False, indexed=False, searchable=False, vfunc=None, readOnly=False, visible=True, unique=False, **kwargs)

Bases: object

__dict__ = dict_proxy({'performMagic': <function performMagic>, 'isClonedInstance': False, '__module__': 'server.bones.bone', 'postSavedHandler': <function postSavedHandler>, 'buildDBFilter': <function buildDBFilter>, 'hasDBField': True, 'serialize': <function serialize>, 'getUniquePropertyIndexValue': <function getUniquePropertyIndexValue>, '__dict__': <attribute '__dict__' of 'baseBone' objects>, 'buildDBSort': <function buildDBSort>, 'getSearchTags': <function getSearchTags>, '__weakref__': <attribute '__weakref__' of 'baseBone' objects>, '__init__': <function __init__>, 'getDefaultValue': <function getDefaultValue>, '__setattr__': <function __setattr__>, 'isInvalid': <function isInvalid>, 'getReferencedBlobs': <function getReferencedBlobs>, 'unserialize': <function unserialize>, '__doc__': None, 'postDeletedHandler': <function postDeletedHandler>, 'getSearchDocumentFields': <function getSearchDocumentFields>, 'setBoneValue': <function setBoneValue>, 'fromClient': <function fromClient>, 'type': 'hidden', 'refresh': <function refresh>, 'mergeFrom': <function mergeFrom>})
__init__(descr='', defaultValue=None, required=False, params=None, multiple=False, indexed=False, searchable=False, vfunc=None, readOnly=False, visible=True, unique=False, **kwargs)

Initializes a new Bone.

Parameters:
  • descr (str) – Textual, human-readable description of that bone. Will be translated.
  • defaultValue (mixed) – If set, this bone will be preinitialized with this value
  • required (bool) – If True, the user must enter a valid value for this bone (the server refuses to save the skeleton otherwise)
  • multiple (bool) – If True, multiple values can be given. (ie. n:m relations instead of n:1)
  • indexed (bool) – If True, this bone will be included in indexes. This is needed if you want to run queries against this bone. If False, it will save datastore write-ops.
  • searchable (bool) – If True, this bone will be included in the fulltext search. Can be used without the need of also been indexed.
  • vfunc (callable) – If given, a callable validating the user-supplied value for this bone. This callable must return None if the value is valid, a String containing an meaningfull error-message for the user otherwise.
  • readOnly (bool) – If True, the user is unable to change the value of this bone. If a value for this bone is given along the POST-Request during Add/Edit, this value will be ignored. Its still possible for the developer to modify this value by assigning skel.bone.value.
  • visible (bool) – If False, the value of this bone should be hidden from the user. This does not protect the value from beeing exposed in a template, nor from being transfered to the client (ie to the admin or as hidden-value in html-forms) Again: This is just a hint. It cannot be used as a security precaution.

Note

The kwarg ‘multiple’ is not supported by all bones (fe. selectOneBone)

__module__ = 'server.bones.bone'
__setattr__(key, value)
__weakref__

list of weak references to the object (if defined)

buildDBFilter(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:
Returns:

The modified server.db.Query

buildDBSort(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:
Returns:

The modified server.db.Query

fromClient(valuesCache, name, data)

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

Parameters:
  • name (String) – Our name in the skeleton
  • data (dict) – User-supplied request-data
Returns:

None or str

getDefaultValue()
getReferencedBlobs(valuesCache, name)

Returns the list of blob keys referenced from this bone

getSearchDocumentFields(valuesCache, name)

Returns a list of search-fields (GAE search API) for this bone.

getSearchTags(valuesCache, name)

Returns a list of Strings which will be included in the fulltext-index for this bone.

Note

This function gets only called, if the ViUR internal fulltext-search is used. If you enable the search-API by setting a searchIndex on the skeleton, getSearchDocumentFields is called instead.

Returns:List of Strings
getUniquePropertyIndexValue(valuesCache, name)

Returns an hash for our current value, used to store in the uniqueProptertyValue index.

hasDBField = True
isClonedInstance = False
isInvalid(value)

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

mergeFrom(valuesCache, boneName, otherSkel)

Clones the values from other into this instance

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

postDeletedHandler(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 (String) – Name of this bone
  • key – The old Database Key of hte entity we’ve deleted
postSavedHandler(valuesCache, boneName, skel, key, dbObj)

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

Parameters:
  • boneName (String) – 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
refresh(valuesCache, boneName, skel)

Refresh all values we might have cached from other entities.

serialize(valuesCache, name, entity)

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

Parameters:name (String) – The property-name this bone has in its Skeleton (not the description!)
Returns:dict
setBoneValue(valuesCache, boneName, value, append, *args, **kwargs)

Set our value to ‘value’. Santy-Checks are performed; if the value is invalid, we flip our value back to its original (default) value and return false.

Parameters:
  • valuesCache (dict) – Dictionary with the current values from the skeleton we belong to
  • boneName (object) – The Bone which should be modified
  • value – 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

type = 'hidden'
unserialize(valuesCache, name, expando)

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: String :param expando: An instance of the dictionary-like db.Entity class :type expando: db.Entity :returns: bool

class server.bones.bone.boneFactory(cls, args, kwargs)

Bases: object

IDX = 1
__call__(*args, **kwargs)
__dict__ = dict_proxy({'__module__': 'server.bones.bone', 'IDX': 1, '__dict__': <attribute '__dict__' of 'boneFactory' objects>, '__repr__': <function __repr__>, '__call__': <function __call__>, '__weakref__': <attribute '__weakref__' of 'boneFactory' objects>, '__doc__': None, '__init__': <function __init__>})
__init__(cls, args, kwargs)
__module__ = 'server.bones.bone'
__repr__()
__weakref__

list of weak references to the object (if defined)

server.bones.bone.getSystemInitialized()
server.bones.bone.setSystemInitialized()

booleanBone

A simple yes/no switch.

class server.bones.booleanBone.booleanBone(defaultValue=False, *args, **kwargs)

Bases: server.bones.bone.baseBone

__init__(defaultValue=False, *args, **kwargs)
__module__ = 'server.bones.booleanBone'
buildDBFilter(name, skel, dbFilter, rawFilter, prefix=None)
fromClient(valuesCache, name, data)

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:

str or None

static generageSearchWidget(target, name='BOOLEAN BONE')
serialize(valuesCache, name, entity)

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
trueStrs = ['True', '1', 'yes']
type = 'bool'
unserialize(valuesCache, name, expando)

Inverse of serialize. Evaluates whats read from the datastore and populates this bone accordingly.

Parameters:
  • name (str) – The property-name this bone has in its Skeleton (not the description!)
  • expando (db.Entity) – An instance of the dictionary-like db.Entity class
Returns:

bool

captchaBone

If used, requires the solving of its captcha before the entry can be stored / formmailer sends it’s email. Not stored inside the database.

class server.bones.captchaBone.captchaBone(publicKey=None, privateKey=None, *args, **kwargs)

Bases: server.bones.bone.baseBone

__init__(publicKey=None, privateKey=None, *args, **kwargs)
__module__ = 'server.bones.captchaBone'
fromClient(valuesCache, name, data)

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 (String) – Our name in the skeleton
  • data (Dict) – User-supplied request-data
Returns:

None or String

serialize(valuesCache, name, entity)
type = 'captcha'
unserialize(valuesCache, name, values)

credentialBone

Can be used to store data that a user can supply, but that should never leak in any output (= Write only). To retrieve the value stored, replace this bone with a stringBone or use db.Get().

class server.bones.credentialBone.credentialBone(*args, **kwargs)

Bases: server.bones.stringBone.stringBone

A bone for storing credentials. This is always empty if read from the database. If its saved, its ignored if its values is still empty. If its value is not empty, it will update the value in the database

__init__(*args, **kwargs)
__module__ = 'server.bones.credentialBone'
serialize(valuesCache, name, entity)

Update the value only if a new value is supplied.

type = 'str.credential'
unserialize(valuesCache, name, values)

We’ll never read our value from the database.

colorBone

A color-picker.

class server.bones.colorBone.colorBone(mode='rgb', *args, **kwargs)

Bases: server.bones.bone.baseBone

__init__(mode='rgb', *args, **kwargs)
__module__ = 'server.bones.colorBone'
fromClient(valuesCache, name, data)

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:

str or None

type = 'color'

dateBone

Stores a date, a time or both. Supports localizing (representing it’s value in the users native timezone).

class server.bones.dateBone.ExtendedDateTime

Bases: datetime.datetime

__dict__ = dict_proxy({'__module__': 'server.bones.dateBone', 'totimestamp': <function totimestamp>, '__dict__': <attribute '__dict__' of 'ExtendedDateTime' objects>, '__weakref__': <attribute '__weakref__' of 'ExtendedDateTime' objects>, '__doc__': None, 'strftime': <function strftime>})
__module__ = 'server.bones.dateBone'
__weakref__

list of weak references to the object (if defined)

strftime(format)

Provides correct localized names for directives like %a which dont get translated on GAE properly This currently replaces %a, %A, %b, %B, %c, %x and %X.

Parameters:format (str) – String containing the Format to apply.
Returns:str
totimestamp()

Converts this DateTime-Object back into Unixtime

class server.bones.dateBone.dateBone(creationMagic=False, updateMagic=False, date=True, time=True, localize=False, *args, **kwargs)

Bases: server.bones.bone.baseBone

__init__(creationMagic=False, updateMagic=False, date=True, time=True, localize=False, *args, **kwargs)

Initializes a new dateBone.

Parameters:
  • creationMagic (bool) – Use the current time as value when creating an entity; ignoring this bone if the entity gets updated.
  • updateMagic (bool) – Use the current time whenever this entity is saved.
  • date (bool) – Should this bone contain a date-information?
  • time (bool) – Should this bone contain time information?
  • localize (bool) – Automatically convert this time into the users timezone? Only valid if this bone contains date and time-information!
__module__ = 'server.bones.dateBone'
buildDBFilter(name, skel, dbFilter, rawFilter, prefix=None)
fromClient(valuesCache, name, data)

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:

str or None

static generageSearchWidget(target, name='DATE BONE', mode='range')
guessTimeZone()

Guess the timezone the user is supposed to be in. If it cant be guessed, a safe default (UTC) is used

isInvalid(value)

Ensure that year is >= 1900 Otherwise strftime will break later on.

performMagic(valuesCache, name, isAdd)
readLocalized(value)

Read a (probably localized Value) from the Client and convert it back to UTC

serialize(valuesCache, name, entity)
setLocalized(valuesCache, name, value)

Converts a Date read from DB (UTC) to the requesters local time

type = 'date'
unserialize(valuesCache, name, expando)

emailBone

A stringBone that verifies it’s value represent a semantically correct email address. Provides no guarantee of existence or deliverability, just checks if it looks valid.

class server.bones.emailBone.emailBone(caseSensitive=True, multiple=False, languages=None, *args, **kwargs)

Bases: server.bones.stringBone.stringBone

__module__ = 'server.bones.emailBone'
isInvalid(value)
type = 'str.email'

fileBone

Reference to a file. Must be used for files as the default relationalBone won’t claim a lock on this file.

class server.bones.fileBone.fileBone(format='$(dest.name)', *args, **kwargs)

Bases: server.bones.treeItemBone.treeItemBone

__init__(format='$(dest.name)', *args, **kwargs)
__module__ = 'server.bones.fileBone'
getReferencedBlobs(valuesCache, name)
kind = 'file'
refKeys = ['name', 'key', 'meta_mime', 'metamime', 'mimetype', 'dlkey', 'servingurl', 'size']
refresh(valuesCache, boneName, skel)

Refresh all values we might have cached from other entities.

type = 'relational.treeitem.file'
unserialize(valuesCache, name, expando)

hierarchyBone

A relationalBone that picks it’s references from a hierarchy application. .. automodule:: server.bones.hierarchyBone

show-inheritance:
 
members:
undoc-members:
private-members:
 
special-members:
 

numericBone

Stores integers or floats.

class server.bones.numericBone.numericBone(precision=0, min=-1073741824, max=1073741824, *args, **kwargs)

Bases: server.bones.bone.baseBone

Holds numeric values. Can be used for ints and floats. For floats, the precision can be specified in decimal-places.

__init__(precision=0, min=-1073741824, max=1073741824, *args, **kwargs)

Initializes a new NumericBone.

Parameters:
  • precision (int) – How may decimal places should be saved. Zero casts the value to int instead of float.
  • min (float) – Minimum accepted value (including).
  • max (float) – Maximum accepted value (including).
__module__ = 'server.bones.numericBone'
buildDBFilter(name, skel, dbFilter, rawFilter, prefix=None)
fromClient(valuesCache, name, data)

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 (String) – Our name in the skeleton
  • data (Dict) – User-supplied request-data
Returns:

None or String

static generageSearchWidget(target, name='NUMERIC BONE', mode='range')
serialize(valuesCache, name, entity)
type = 'numeric'
unserialize(valuesCache, name, expando)

passwordBone

Safely stores passwords. All passwords are hashed with PBKDF2 and an randomly choosen salt.

class server.bones.passwordBone.passwordBone(caseSensitive=True, multiple=False, languages=None, *args, **kwargs)

Bases: server.bones.stringBone.stringBone

A bone holding passwords. This is always empty if read from the database. If its saved, its ignored if its values is still empty. If its value is not empty, its hashed (with salt) and only the resulting hash will be written to the database

__module__ = 'server.bones.passwordBone'
isInvalid(value)
minPasswordLength = 8
passwordTestThreshold = 3
passwordTests = [<function <lambda>>, <function <lambda>>, <function <lambda>>, <function <lambda>>]
saltLength = 13
serialize(valuesCache, name, entity)
type = 'password'
unserialize(valuesCache, name, values)
server.bones.passwordBone.pbkdf2(password, salt, iterations=1001, keylen=42)

An implementation of PBKDF2 (http://wikipedia.org/wiki/PBKDF2)

Mostly based on the implementation of https://github.com/mitsuhiko/python-pbkdf2/blob/master/pbkdf2.py

Copyright:
  1. Copyright 2011 by Armin Ronacher.
License:

BSD, see LICENSE for more details.

randomSliceBone

Stores no data but provides orderby=random functionality.

server.bones.randomSliceBone.random() → x in the interval [0, 1).
class server.bones.randomSliceBone.randomSliceBone(indexed=True, visible=False, readOnly=True, slices=2, sliceSize=0.5, *args, **kwargs)

Bases: server.bones.bone.baseBone

Simulates the orderby=random from SQL. If you sort by this bone, the query will return a random set of elements from that query.

__init__(indexed=True, visible=False, readOnly=True, slices=2, sliceSize=0.5, *args, **kwargs)

Initializes a new randomSliceBone.

__module__ = 'server.bones.randomSliceBone'
buildDBSort(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 handle malformed data!

This function is somewhat special as it doesn’t just change in which order the selected Elements are being returned - but also changes which Elements are beeing returned (=> a random selection)

Parameters:
Returns:

The modified server.db.Query

calculateInternalMultiQueryAmount(targetAmount)

Tells server.db.Query How much entries should be fetched in each subquery.

Parameters:targetAmount (int) – How many entries shall be returned from db.Query
Returns:The amount of elements db.Query should fetch on each subquery
Return type:int
customMultiQueryMerge(dbFilter, result, targetAmount)

Randomly returns ‘targetAmount’ elements from ‘result’

Parameters:
  • dbFilter – The db.Query calling this function
  • result (list of list of server.db.Entity) – The list of results for each subquery we’ve run
  • targetAmount (int) – How many results should be returned from db.Query
Type:

dbFilter: server.db.Query

Returns:

List of elements which should be returned from db.Query

Return type:

list of server.db.Entity

serialize(name, entity)

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

This time, we just ignore whatever is set on this bone and write a randomly chosen float [0..1) as value for this bone.

Parameters:name (String) – The property-name this bone has in its Skeleton (not the description!)
Returns:dict
type = 'randomslice'

relationalBone

References another entry.

class server.bones.relationalBone.relationalBone(kind=None, module=None, refKeys=None, parentKeys=None, multiple=False, format='$(dest.name)', using=None, *args, **kwargs)

Bases: server.bones.bone.baseBone

This is our magic class implementing relations.

This implementation is read-efficient, e.g. filtering by relational-properties only costs an additional small-op for each entity returned. However, it costs several more write-ops for writing an entity to the db. (These costs are somewhat around additional (4+len(refKeys)+len(parentKeys)) write-ops for each referenced property) for multiple=True relationalBones and (4+len(refKeys)) for n:1 relations)

So don’t use this if you expect data being read less frequently than written! (Sorry, we don’t have a write-efficient method yet) To speedup writes to (maybe) referenced entities, information in these relations isn’t updated instantly. Once a skeleton is updated, a deferred task is kicked off which updates the references to that skeleton (if any). As a result, you might see stale data until this task has been finished.

Example:

  • Entity A references Entity B.
  • Both have a property “name”.
  • Entity B gets updated (it name changes).
  • As “A” has a copy of entity “B”s values, you’ll see “B”s old name inside the values of the relationalBone when fetching entity A.

If you filter a list by relational properties, this will also use the old data! (Eg. filtering A’s list by B’s new name won’t return any result)

__init__(kind=None, module=None, refKeys=None, parentKeys=None, multiple=False, format='$(dest.name)', using=None, *args, **kwargs)

Initialize a new relationalBone.

Parameters:
  • kind (String) – KindName of the referenced property.
  • module – Name of the modul which should be used to select entities of kind “type”. If not set, the value of “type” will be used (the kindName must match the moduleName)
  • refKeys (List of Strings) – A list of properties to include from the referenced property. These properties will be avaiable in the template without having to fetch the referenced property. Filtering is also only possible by properties named here!
  • parentKeys (List of Strings) – A list of properties from the current skeleton to include. If mixing filtering by relational properties and properties of the class itself, these must be named here.
  • multiple (False) – If True, allow referencing multiple Elements of the given class. (Eg. n:n-relation. otherwise its n:1 )
  • format (String) – Hint for the admin how to display such an relation. See admin/utils.py:formatString for more information
__module__ = 'server.bones.relationalBone'
_restoreValueFromDatastore(val)

Restores one of our values (including the Rel- and Using-Skel) from the serialized data read from the datastore :param value: Json-Encoded datastore property :return: Our Value (with restored RelSkel and using-Skel)

_rewriteQuery(name, skel, dbFilter, rawFilter)

Rewrites a datastore query to operate on “viur-relations” instead of the original kind. This is needed to perform relational queries on n:m relations.

buildDBFilter(name, skel, dbFilter, rawFilter, prefix=None)
buildDBSort(name, skel, dbFilter, rawFilter)
filterHook(name, query, param, value)

Hook installed by buildDbFilter. This rewrites all filters added to the query after buildDbFilter has been run to match the layout of our viur-relations index. Also performs sanity checks wherever this query is possible at all.

fromClient(valuesCache, name, data)

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 (String) – Our name in the skeleton
  • data (Dict) – User-supplied request-data
Returns:

None or String

getReferencedBlobs(valuesCache, name)

Returns the list of blob keys referenced from this bone

getSearchDocumentFields(valuesCache, name)
getSearchTags(values, key)
isInvalid(key)
kind = None
orderHook(name, query, orderings)

Hook installed by buildDbFilter. This rewrites all orderings added to the query after buildDbFilter has been run to match the layout of our viur-relations index. Also performs sanity checks wherever this query is possible at all.

parentKeys = ['key', 'name']
postDeletedHandler(skel, key, id)
postSavedHandler(valuesCache, boneName, skel, key, dbfields)
refKeys = ['key', 'name']
refresh(valuesCache, boneName, skel)

Refresh all values we might have cached from other entities.

serialize(valuesCache, name, entity)
setBoneValue(valuesCache, boneName, value, append, *args, **kwargs)

Set our value to ‘value’. Santy-Checks are performed; if the value is invalid, we flip our value back to its original (default) value and return false.

Parameters:
  • valuesCache (dict) – Dictionary with the current values from the skeleton we belong to
  • boneName (object) – The Bone which should be modified
  • value – 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

type = 'relational'
unserialize(valuesCache, name, expando)

selectCountryBone

SelectOneBone with values preset to a list of countries. You can choose between ISO2 and ISO3 codes. It’s possible to switch between ISO2 and ISO3 codes; a rebuildSearchIndex will convert the values accordingly.

class server.bones.selectCountryBone.selectCountryBone(codes=2, *args, **kwargs)

Bases: server.bones.selectOneBone.selectOneBone

ISO2 = 2
ISO3 = 3
__init__(codes=2, *args, **kwargs)
__module__ = 'server.bones.selectCountryBone'
unserialize(valuesCache, name, expando)

selectMultiBone

Select multiple elements from a predefined list.

class server.bones.selectMultiBone.selectAccessMultiBone(*args, **kwargs)

Bases: server.bones.selectMultiBone.selectMultiBone

__init__(*args, **kwargs)

Creates a new AccessSelectMultiBone. This bone encapulates elements that have a postfix “-add”, “-delete”, “-view” and “-edit” and visualizes them as a compbound unit.

This bone is normally used in the userSkel only to provide a user data access right selector.

__module__ = 'server.bones.selectMultiBone'
type = 'selectmulti.access'
class server.bones.selectMultiBone.selectMultiBone(defaultValue=[], values={}, *args, **kwargs)

Bases: server.bones.bone.baseBone

__init__(defaultValue=[], values={}, *args, **kwargs)

Creates a new SelectMultiBone

Parameters:
  • defaultValue (List) – List of keys which will be checked by default
  • values (Dict) – Dict of key->value pairs from which the user can choose from. Values will be translated
  • sortBy (String) – Either “keys” or “values”. Sorts the values on clientside either by keys or by ( translated) values
__module__ = 'server.bones.selectMultiBone'
fromClient(valuesCache, name, data)

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 (String) – Our name in the skeleton
  • data (Dict) – User-supplied request-data
Returns:

None or String

static generageSearchWidget(target, name='SELECTMULTI BONE', values=[])
serialize(valuesCache, name, entity)
type = 'selectmulti'
unserialize(valuesCache, name, expando)

selectOneBone

Select one element from a predefined list.

class server.bones.selectOneBone.selectOneBone(values={}, defaultValue=None, *args, **kwargs)

Bases: server.bones.bone.baseBone

__init__(values={}, defaultValue=None, *args, **kwargs)

Creates a new selectOneBone

Parameters:
  • defaultValue (List) – List of keys which will be checked by default
  • values (Dict) – Dict of key->value pairs from which the user can choose from. Values will be translated
  • sortBy (String) –

    Either “keys” or “values”. Sorts the values on clientside either by keys or by (translated) values

    Deprecated since version 2.0: Supply an orderedDict instead

__module__ = 'server.bones.selectOneBone'
buildDBFilter(name, skel, dbFilter, rawFilter, prefix=None)
fromClient(valuesCache, name, data)

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

Parameters:
  • name (String) – Our name in the skeleton
  • data (Dict) – User-supplied request-data
Returns:

None or String

static generageSearchWidget(target, name='SELECTONE BONE', values=[])
type = 'selectone'

spatialBone

Stores a latitude/longitude pair and provides proximity-search.

server.bones.spatialBone.haversine(lat1, lng1, lat2, lng2)

Calculates the distance between two points on Earth given by (lat1,lng1) and (lat2, lng2) in Meter. See https://en.wikipedia.org/wiki/Haversine_formula

Returns:Distance in Meter
class server.bones.spatialBone.spatialBone(boundsLat, boundsLng, gridDimensions, indexed=True, *args, **kwargs)

Bases: server.bones.bone.baseBone

Allows to query by Elements close to a given position. Prior to use, you must specify for which region of the map the index should be build. This region should be as small as possible for best accuracy. You cannot use the whole world, as no boundary wraps are been performed. GridDimensions specifies into how many sub-regions the map will be split. Results further away than the size of these sub-regions won’t be considered within a search by this algorithm.

Example:
If you use this bone to query your data for the nearest pubs, you might want to this algorithm to consider results up to 100km distance, but not results that are 500km away. Setting the size of these sub-regions to roughly 100km width/height allows this algorithm to exclude results further than 200km away on database-query-level, therefore drastically improving performance and reducing costs per query.

Example region: Germany: boundsLat=(46.988, 55.022), boundsLng=(4.997, 15.148)

__init__(boundsLat, boundsLng, gridDimensions, indexed=True, *args, **kwargs)

Initializes a new spatialBone.

Parameters:
  • boundsLat ((int, int)) – Outer bounds (Latitude) of the region we will search in.
  • boundsLng ((int, int)) – Outer bounds (Latitude) of the region we will search in.
  • gridDimensions ((int, int)) – Number of sub-regions the map will be divided in
__module__ = 'server.bones.spatialBone'
buildDBFilter(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)

For detailed information, how this geo-spatial search works, see the ViUR documentation.

Parameters:
Returns:

The modified server.db.Query

calculateInternalMultiQueryAmount(targetAmount)

Tells server.db.Query How much entries should be fetched in each subquery.

Parameters:targetAmount (int) – How many entries shall be returned from db.Query
Returns:The amount of elements db.Query should fetch on each subquery
Return type:int
customMultiQueryMerge(name, lat, lng, dbFilter, result, targetAmount)

Randomly returns ‘targetAmount’ elements from ‘result’

Parameters:
  • dbFilter – The db.Query calling this function
  • result (list of list of server.db.Entity) – The list of results for each subquery we’ve run
  • targetAmount (int) – How many results should be returned from db.Query
Type:

dbFilter: server.db.Query

Returns:

List of elements which should be returned from db.Query

Return type:

list of server.db.Entity

getGridSize()
Returns:the size of our sub-regions in (fractions-of-latitude, fractions-of-longitude)
Return type:(float, flot)
isInvalid(value)

Tests, if the point given by ‘value’ is inside our boundaries. We’ll reject all values outside that region. :param value: (latitude, longitude) of the location of this entry. :type value: (float, float) :return: An error-description or False if the value is valid :rtype: str | False

serialize(valuesCache, name, entity)

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

Parameters:name (String) – The property-name this bone has in its Skeleton (not the description!)
Returns:dict
type = 'spatial'
unserialize(valuesCache, name, expando)

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: String :param expando: An instance of the dictionary-like db.Entity class :type expando: db.Entity :returns: bool

stringBone

Stores a short text without formatting. Can hold multiple texts per language.

class server.bones.stringBone.LanguageWrapper(languages)

Bases: dict

Wrapper-class for a multi-language value. Its a dictionary, allowing accessing each stored language, but can also be used as a string, in which case it tries to guess the correct language.

__dict__ = dict_proxy({'__module__': 'server.bones.stringBone', 'resolve': <function resolve>, '__str__': <function __str__>, '__dict__': <attribute '__dict__' of 'LanguageWrapper' objects>, '__weakref__': <attribute '__weakref__' of 'LanguageWrapper' objects>, '__doc__': '\n\t\tWrapper-class for a multi-language value.\n\t\tIts a dictionary, allowing accessing each stored language,\n\t\tbut can also be used as a string, in which case it tries to\n\t\tguess the correct language.\n\t', '__init__': <function __init__>})
__init__(languages)
__module__ = 'server.bones.stringBone'
__str__()
__weakref__

list of weak references to the object (if defined)

resolve()

Causes this wrapper to evaluate to the best language available for the current request.

Returns:str|list of str
Return type:str|list of str
class server.bones.stringBone.stringBone(caseSensitive=True, multiple=False, languages=None, *args, **kwargs)

Bases: server.bones.bone.baseBone

__init__(caseSensitive=True, multiple=False, languages=None, *args, **kwargs)
__module__ = 'server.bones.stringBone'
buildDBFilter(name, skel, dbFilter, rawFilter, prefix=None)
buildDBSort(name, skel, dbFilter, rawFilter)
fromClient(valuesCache, name, data)

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

Parameters:
Returns:

str or None

static generageSearchWidget(target, name='STRING BONE', mode='equals')
getSearchDocumentFields(valuesCache, name)

Returns a list of search-fields (GAE search API) for this bone.

getSearchTags(valuesCache, name)
getUniquePropertyIndexValue(valuesCache, name)

Returns an hash for our current value, used to store in the uniqueProptertyValue index.

serialize(valuesCache, name, entity)
type = 'str'
unserialize(valuesCache, name, expando)

Inverse of serialize. Evaluates whats read from the datastore and populates this bone accordingly.

Parameters:

textBone

Stores longer texts that may contain format directives. Can hold multiple texts per language.

class server.bones.textBone.HtmlSerializer(validHtml=None)

Bases: HTMLParser.HTMLParser

__init__(validHtml=None)
__module__ = 'server.bones.textBone'
cleanup()

Append missing closing tags

handle_charref(name)
handle_data(data)
handle_endtag(tag)
handle_entityref(name)
handle_starttag(tag, attrs)

Delete all tags except for legal ones

santinize(instr)
class server.bones.textBone.textBone(validHtml=<class server.bones.textBone.__undefinedC__>, indexed=False, languages=None, maxLength=200000, *args, **kwargs)

Bases: server.bones.bone.baseBone

__init__(validHtml=<class server.bones.textBone.__undefinedC__>, indexed=False, languages=None, maxLength=200000, *args, **kwargs)
__module__ = 'server.bones.textBone'
class __undefinedC__
__module__ = 'server.bones.textBone'
fromClient(valuesCache, name, data)

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 (String) – Our name in the skeleton
  • data (Dict) – User-supplied request-data
Returns:

None or String

static generageSearchWidget(target, name='TEXT BONE', mode='equals')
getReferencedBlobs(valuesCache, name)

Test for /file/download/ links inside our text body. Doesn’t check for actual <a href=> or <img src=> yet.

getSearchDocumentFields(valuesCache, name)

Returns a list of search-fields (GAE search API) for this bone.

getSearchTags(valuesCache, name)
isInvalid(value)

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

serialize(valuesCache, name, entity)

Fills this bone with user generated content

Parameters:
  • name (str) – The property-name this bone has in its Skeleton (not the description!)
  • entity (server.db.Entity) – An instance of the dictionary-like db.Entity class
Returns:

the modified server.db.Entity

type = 'text'
unserialize(valuesCache, name, expando)

Inverse of serialize. Evaluates whats read from the datastore and populates this bone accordingly.

Parameters:
  • name (str) – The property-name this bone has in its Skeleton (not the description!)
  • expando (db.Entity) – An instance of the dictionary-like db.Entity class

treeDirBone

RelationalBone that selects a node from a tree application.

class server.bones.treeDirBone.treeDirBone(kind=None, format='$(dest.name)', *args, **kwargs)

Bases: server.bones.relationalBone.relationalBone

__init__(kind=None, format='$(dest.name)', *args, **kwargs)
__module__ = 'server.bones.treeDirBone'

treeItemBone

RelationalBone that selects a leaf from a tree application.

class server.bones.treeItemBone.treeItemBone(*args, **kwargs)

Bases: server.bones.relationalBone.relationalBone

__init__(*args, **kwargs)
__module__ = 'server.bones.treeItemBone'

userBone

RelationalBone that selects a user from the user-module.

class server.bones.userBone.userBone(creationMagic=False, updateMagic=False, *args, **kwargs)

Bases: server.bones.relationalBone.relationalBone

__init__(creationMagic=False, updateMagic=False, *args, **kwargs)
__module__ = 'server.bones.userBone'
datafields = ['name']
kind = 'user'
performMagic(valuesCache, key, isAdd, *args, **kwargs)