renderers

html

class server.render.html.default.Render(parent=None, *args, **kwargs)

The core jinja2 render.

This is the bridge between your ViUR modules and your templates. First, the default jinja2-api is exposed to your templates. See http://jinja.pocoo.org/ for more information. Second, we’ll pass data das global variables to templates depending on the current action.

  • For list() we’ll pass skellist - a server.render.jinja2.default.SkelListWrapper instance
  • For view(): skel - a dictionary with values from the skeleton prepared for use inside html
  • For add()/edit: a dictionary as skel with values, structure and errors as keys.

Third, a bunch of global filters (like urlencode) and functions (getEntry, ..) are available to templates.

See the ViUR Documentation for more information about functions and data available to jinja2 templates.

Its possible for modules to extend the list of filters/functions available to templates by defining a function called jinjaEnv. Its called from the render when the environment is first created and can extend/override the functionality exposed to templates.

class KeyValueWrapper(key, descr)

This holds one Key-Value pair for selectOne/selectMulti Bones.

It allows to directly treat the key as string, but still makes the translated description of that key available.

Render.add(skel, tpl=None, *args, **kwargs)

Renders a page for adding an entry.

The template must construct the HTML-form on itself; the required information are passed via skel.structure, skel.value and skel.errors.

A jinja2-macro, which builds such kind of forms, is shipped with the server.

Any data in **kwargs is passed unmodified to the template.

Parameters:
  • skel (server.db.skeleton.Skeleton) – Skeleton of the entry which should be created.
  • tpl (str) – Name of a different template, which should be used instead of the default one.
Returns:

Returns the emitted HTML response.

Return type:

str

Render.addDirSuccess(rootNode, path, dirname, *args, **kwargs)

Renders a page, informing that the directory has been successfully created.

Parameters:
  • rootNode (str) – RootNode-key in which the directory has been created
  • path (str) – Path in which the directory has been created
  • dirname (str) – Name of the newly created directory
Returns:

Returns the emitted HTML response.

Return type:

str

Render.addItemSuccess(skel, *args, **kwargs)

Renders a page, informing that the entry has been successfully created.

Parameters:skel (server.db.skeleton.Skeleton) – Skeleton which contains the data of the new entity
Returns:Returns the emitted HTML response.
Return type:str
Render.checkForOldLinePrefix(fn)

This method checks the given template for lines starting with “##” - the old, now unsupported Line-Prefix. Bail out if such prefixes are used. This is a temporary safety measure; will be removed after 01.05.2017.

Parameters:fn – The filename to check
Returns:
Render.cloneSuccess(tpl=None, *args, **kwargs)

Renders a page informing that the items sortindex was successfully changed.

Parameters:
  • obj (ndb.Expando) – ndb.Expando instance of the item that was changed
  • tpl (str) – Name of a different template, which should be used instead of the default one
Returns:

Returns the emitted HTML response.

Return type:

str

Render.collectSkelData(skel)

Prepares values of one server.db.skeleton.Skeleton or a list of skeletons for output.

Parameters:skel (server.db.skeleton.Skeleton) – Skeleton which contents will be processed.
Returns:A dictionary or list of dictionaries.
Return type:dict | list
Render.copySuccess(srcrepo, srcpath, name, destrepo, destpath, type, deleteold, *args, **kwargs)

Renders a page, informing that an entry has been successfully copied/moved.

Parameters:
  • srcrepo (str) – RootNode-key from which has been copied/moved
  • srcpath (str) – Path from which the entry has been copied/moved
  • name (str) – Name of the entry which has been copied/moved
  • destrepo (str) – RootNode-key to which has been copied/moved
  • destpath (str) – Path to which the entries has been copied/moved
  • type (string) – “entry”: Copy/Move an entry, everything else: Copy/Move an directory
  • deleteold (str) – “0”: Copy, “1”: Move
Returns:

Returns the emitted HTML response.

Return type:

str

Render.deleteSuccess(*args, **kwargs)

Renders a page, informing that the entry has been successfully deleted.

The provided parameters depend on the application calling this: List and Hierarchy pass the id of the deleted entry, while Tree passes the rootNode and path.

Returns:Returns the emitted HTML response.
Return type:str
Render.edit(skel, tpl=None, **kwargs)

Renders a page for modifying an entry.

The template must construct the HTML-form on itself; the required information are passed via skel.structure, skel.value and skel.errors.

A jinja2-macro, which builds such kind of forms, is shipped with the server.

Any data in **kwargs is passed unmodified to the template.

Parameters:
  • skel (server.db.skeleton.Skeleton) – Skeleton of the entry which should be modified.
  • tpl (str) – Name of a different template, which should be used instead of the default one.
Returns:

Returns the emitted HTML response.

Return type:

str

Render.editItemSuccess(skel, *args, **kwargs)

Renders a page, informing that the entry has been successfully modified.

Parameters:skel (server.db.skeleton.Skeleton) – Skeleton which contains the data of the modified entity
Returns:Returns the emitted HTML response.
Return type:str
Render.getEnv()

Constucts the Jinja2 environment.

If an application specifies an jinja2Env function, this function can alter the environment before its used to parse any template.

Returns:Extended Jinja2 environment.
Return type:jinja2.Environment
Render.getLoaders()

Return the list of Jinja2 loaders which should be used.

May be overridden to provide an alternative loader (e.g. for fetching templates from the datastore).

Render.getTemplateFileName(template, ignoreStyle=False)

Returns the filename of the template.

This function decides in which language and which style a given template is rendered. The style is provided as get-parameters for special-case templates that differ from their usual way.

It is advised to override this function in case that server.render.jinja2.default.Render.getLoaders() is redefined.

Parameters:
  • template (str) – The basename of the template to use.
  • ignoreStyle (bool) – Ignore any maybe given style hints.
Returns:

Filename of the template

Return type:

str

Render.list(skellist, tpl=None, **kwargs)

Renders a list of entries.

Any data in **kwargs is passed unmodified to the template.

Parameters:
  • skellist (server.db.skeleton.SkelList) – List of Skeletons with entries to display.
  • tpl – Name of a different template, which should be used instead of the default one.
Param:

tpl: str

Returns:

Returns the emitted HTML response.

Return type:

str

Render.listRootNodeContents(subdirs, entries, tpl=None, **kwargs)

Renders the contents of a given RootNode.

This differs from list(), as one level in the tree-application may contains two different child-types: Entries and folders.

Parameters:
  • subdirs – List of (sub-)directories on the current level
  • entries (server.db.skeleton.SkelList) – List of entries of the current level
  • tpl – Name of a different template, which should be used instead of the default one
Param:

tpl: str

Returns:

Returns the emitted HTML response.

Return type:

str

Render.listRootNodes(repos, tpl=None, **kwargs)

Renders a list of available repositories.

Parameters:
  • repos (list) – List of repositories (dict with “key”=>Repo-Key and “name”=>Repo-Name)
  • tpl – Name of a different template, which should be used instead of the default one.
Param:

tpl: str

Returns:

Returns the emitted HTML response.

Return type:

str

Render.renameSuccess(rootNode, path, src, dest, *args, **kwargs)

Renders a page, informing that the entry has been successfully renamed.

Parameters:
  • rootNode (str) – RootNode-key in which the entry has been renamed
  • path (str) – Path in which the entry has been renamed
  • src (str) – Old name of the entry
  • dest (str) – New name of the entry
Returns:

Returns the emitted HTML response.

Return type:

str

Render.renderBoneStructure(bone)

Renders the structure of a bone.

This function is used by renderSkelStructure(). can be overridden and super-called from a custom renderer.

Parameters:bone (Any bone that inherits from server.bones.base.baseBone.) – The bone which structure should be rendered.
Returns:A dict containing the rendered attributes.
Return type:dict
Render.renderBoneValue(bone, skel, key)

Renders the value of a bone.

This function is used by collectSkelData(). It can be overridden and super-called from a custom renderer.

Parameters:bone (Any bone that inherits from server.bones.base.baseBone.) – The bone which value should be rendered.
Returns:A dict containing the rendered attributes.
Return type:dict
Render.renderEmail(skel, tpl, dests, **kwargs)

Renders an email.

Parameters:
  • skel (server.db.skeleton.Skeleton | dict) – Skeleton or dict which data to supply to the template.
  • tpl (str) – Name of the email-template to use. If this string is longer than 100 characters, this string is interpreted as the template contents instead of its filename.
  • dests (list | str) – Destination recipients.
Returns:

Returns a tuple consisting of email header and body.

Return type:

str, str

Render.renderSkelStructure(skel)

Dumps the structure of a server.db.skeleton.Skeleton.

Parameters:skel (server.db.skeleton.Skeleton) – Skeleton which structure will be processed.
Returns:The rendered dictionary.
Return type:dict
Render.reparentSuccess(obj, tpl=None, **kwargs)

Renders a page informing that the item was successfully moved.

Parameters:
  • obj (ndb.Expando) – ndb.Expando instance of the item that was moved.
  • tpl (str) – Name of a different template, which should be used instead of the default one
Render.setIndexSuccess(obj, tpl=None, *args, **kwargs)

Renders a page informing that the items sortindex was successfully changed.

Parameters:
  • obj (ndb.Expando) – ndb.Expando instance of the item that was changed
  • tpl (str) – Name of a different template, which should be used instead of the default one
Returns:

Returns the emitted HTML response.

Return type:

str

Render.view(skel, tpl=None, **kwargs)

Renders a single entry.

Any data in **kwargs is passed unmodified to the template.

Parameters:
  • skel – Skeleton to be displayed.
  • tpl – Name of a different template, which should be used instead of the default one.
Param:

tpl: str

Returns:

Returns the emitted HTML response.

Return type:

str

json

class server.render.json.default.DefaultRender(parent=None, *args, **kwargs)
renderBoneStructure(bone)

Renders the structure of a bone.

This function is used by renderSkelStructure. can be overridden and super-called from a custom renderer.

Parameters:bone (Any bone that inherits from server.bones.base.baseBone.) – The bone which structure should be rendered.
Returns:A dict containing the rendered attributes.
Return type:dict
renderBoneValue(bone, skel, key)

Renders the value of a bone.

This function is used by collectSkelData(). It can be overridden and super-called from a custom renderer.

Parameters:bone (Any bone that inherits from server.bones.base.baseBone.) – The bone which value should be rendered.
Returns:A dict containing the rendered attributes.
Return type:dict
renderSkelStructure(skel)

Dumps the structure of a server.db.skeleton.Skeleton.

Parameters:skel (server.db.skeleton.Skeleton) – Skeleton which structure will be processed.
Returns:The rendered dictionary.
Return type:dict
renderSkelValues(skel)

Prepares values of one server.db.skeleton.Skeleton or a list of skeletons for output.

Parameters:skel (server.db.skeleton.Skeleton) – Skeleton which contents will be processed.
Returns:A dictionary or list of dictionaries.
Return type:dict