core.render.html

Package Contents

Classes

default

The core jinja2 render.

user

The core jinja2 render.

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

Bases: object

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.

kind = html
listTemplate = list
viewTemplate = view
addTemplate = add
editTemplate = edit
addSuccessTemplate = add_success
editSuccessTemplate = edit_success
deleteSuccessTemplate = delete_success
listRepositoriesTemplate = list_repositories
listRootNodeContentsTemplate = list_rootNode_contents
addDirSuccessTemplate = add_dir_success
renameSuccessTemplate = rename_success
copySuccessTemplate = copy_success
reparentSuccessTemplate = reparent_success
setIndexSuccessTemplate = setindex_success
cloneSuccessTemplate = clone_success
__haveEnvImported_ = False
getTemplateFileName(self, 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

getLoaders(self)

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

renderBoneStructure(self, 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

renderSkelStructure(self, 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

renderBoneValue(self, bone, skel, key, boneValue, isLanguageWrapped: bool = False)

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

collectSkelData(self, 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

Deprecated since version 3.0.0: This method is deprecated since ViUR 3.0. Instead, attach a renderPreparation method to the skeleton and pass the skeleton itself.

add(self, skel, tpl=None, params=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.

  • params (object) – Optional data that will be passed unmodified to the template

Returns

Returns the emitted HTML response.

Return type

str

edit(self, skel, tpl=None, params=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.

  • params (object) – Optional data that will be passed unmodified to the template

Returns

Returns the emitted HTML response.

Return type

str

addSuccess(self, skel, tpl=None, params=None, *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

  • tpl (str) – Name of a different template, which should be used instead of the default one.

  • params (object) – Optional data that will be passed unmodified to the template

Returns

Returns the emitted HTML response.

Return type

str

editSuccess(self, skel, tpl=None, params=None, *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

  • tpl (str) – Name of a different template, which should be used instead of the default one.

  • params (object) – Optional data that will be passed unmodified to the template

Returns

Returns the emitted HTML response.

Return type

str

deleteSuccess(self, skel, tpl=None, params=None, *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.

Parameters
  • params (object) – Optional data that will be passed unmodified to the template

  • 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

list(self, skellist, tpl=None, params=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.

  • params (object) – Optional data that will be passed unmodified to the template

Param

tpl: str

Returns

Returns the emitted HTML response.

Return type

str

listRootNodes(self, repos, tpl=None, params=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.

  • params (object) – Optional data that will be passed unmodified to the template

Param

tpl: str

Returns

Returns the emitted HTML response.

Return type

str

view(self, skel, tpl=None, params=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.

  • params (object) – Optional data that will be passed unmodified to the template

Param

tpl: str

Returns

Returns the emitted HTML response.

Return type

str

listRootNodeContents(self, subdirs, entries, tpl=None, params=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

  • params (object) – Optional data that will be passed unmodified to the template

Param

tpl: str

Returns

Returns the emitted HTML response.

Return type

str

addDirSuccess(self, rootNode, path, dirname, params=None, *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

  • params (object) – Optional data that will be passed unmodified to the template

Returns

Returns the emitted HTML response.

Return type

str

renameSuccess(self, rootNode, path, src, dest, params=None, *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

  • params (object) – Optional data that will be passed unmodified to the template

Returns

Returns the emitted HTML response.

Return type

str

copySuccess(self, srcrepo, srcpath, name, destrepo, destpath, type, deleteold, params=None, *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 (str) – “entry”: Copy/Move an entry, everything else: Copy/Move an directory

  • deleteold (str) – “0”: Copy, “1”: Move

  • params (object) – Optional data that will be passed unmodified to the template

Returns

Returns the emitted HTML response.

Return type

str

reparentSuccess(self, obj, tpl=None, params=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

  • params (object) – Optional data that will be passed unmodified to the template

setIndexSuccess(self, obj, tpl=None, params=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

  • params (object) – Optional data that will be passed unmodified to the template

Returns

Returns the emitted HTML response.

Return type

str

cloneSuccess(self, tpl=None, params=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

  • params (object) – Optional data that will be passed unmodified to the template

Returns

Returns the emitted HTML response.

Return type

str

renderEmail(self, dests: List[str], file: str = None, template: str = None, skel: Union[None, Dict, viur.core.skeleton.SkeletonInstance, List[viur.core.skeleton.SkeletonInstance]] = None, **kwargs) Tuple[str, str]

Renders an email. Uses the first not-empty line as subject and the remaining template as body.

Parameters
  • dests – Destination recipients.

  • file – The name of a template from the deploy/emails directory.

  • template – This string is interpreted as the template contents. Alternative to load from template file.

  • skel – Skeleton or dict which data to supply to the template.

Returns

Returns the rendered email subject and body.

getEnv(self)

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

class core.render.html.user(parent=None, *args, **kwargs)

Bases: core.render.html.default

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.

loginTemplate = user_login
loginChoicesTemplate = user_login_choices
logoutSuccessTemplate = user_logout_success
loginSuccessTemplate = user_login_success
verifySuccessTemplate = user_verify_success
verifyFailedTemplate = user_verify_failed
passwdRecoverInfoTemplate = user_passwdrecover_info
login_disabled(self, authMethods, tpl=None, **kwargs)
login(self, skel, tpl=None, **kwargs)
loginChoices(self, authMethods, tpl=None, **kwargs)
loginSucceeded(self, tpl=None, **kwargs)
logoutSuccess(self, tpl=None, **kwargs)
verifySuccess(self, skel, tpl=None, **kwargs)
verifyFailed(self, tpl=None, **kwargs)
passwdRecoverInfo(self, msg, skel=None, tpl=None, **kwargs)
passwdRecover(self, *args, **kwargs)