core.render.html.default
¶
Module Contents¶
Classes¶
The core jinja2 render. |
Attributes¶
- core.render.html.default.KeyValueWrapper¶
- class core.render.html.default.Render(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
viur.core.render.jinja2.default.SkelListWrapper
instanceFor 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(template: str, ignoreStyle: bool = False) str ¶
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
viur.core.render.jinja2.default.Render.getLoaders()
is redefined.- Parameters
template – The basename of the template to use.
ignoreStyle – Ignore any maybe given style hints.
- Returns
Filename of the template
- getLoaders() jinja2.ChoiceLoader ¶
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(bone: baseBone) Dict[str, Any] ¶
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.BaseBone
.) – The bone which structure should be rendered.- Returns
A dict containing the rendered attributes.
- renderSkelStructure(skel: viur.core.skeleton.SkeletonInstance) Dict ¶
Dumps the structure of a
viur.core.skeleton.Skeleton
.- Parameters
skel – Skeleton which structure will be processed.
- Returns
The rendered structure.
- renderBoneValue(bone: baseBone, skel: viur.core.skeleton.SkeletonInstance, key: Any, boneValue: Any, isLanguageWrapped: bool = False) Union[List, Dict, KeyValueWrapper, viur.core.i18n.LanguageWrapper, str, None] ¶
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 – The bone which value should be rendered. (inherited from
viur.core.bones.base.baseBone
).skel – The skeleton containing the bone instance.
key – The name of the bone.
boneValue – The value of the bone.
isLanguageWrapped – Is this bone wrapped inside a
LanguageWrapper
?
- Returns
A dict containing the rendered attributes.
- collectSkelData(skel: viur.core.skeleton.SkeletonInstance) Union[Dict, List] ¶
Prepares values of one
viur.core.skeleton.Skeleton
or a list of skeletons for output.- Parameters
skel – Skeleton which contents will be processed.
- Returns
A dictionary or list of dictionaries.
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(skel: viur.core.skeleton.SkeletonInstance, tpl: str = None, params: Any = None, *args, **kwargs) str ¶
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 – Skeleton of the entry which should be created.
tpl – Name of a different template, which should be used instead of the default one.
params – Optional data that will be passed unmodified to the template
- Returns
Returns the emitted HTML response.
- edit(skel: viur.core.skeleton.SkeletonInstance, tpl: str = None, params: Any = None, **kwargs) str ¶
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 – Skeleton of the entry which should be modified.
tpl – Name of a different template, which should be used instead of the default one.
params – Optional data that will be passed unmodified to the template
- Returns
Returns the emitted HTML response.
- addSuccess(skel: viur.core.skeleton.SkeletonInstance, tpl: str = None, params: Any = None, *args, **kwargs) str ¶
Renders a page, informing that the entry has been successfully created.
- Parameters
skel – Skeleton which contains the data of the new entity
tpl – Name of a different template, which should be used instead of the default one.
params – Optional data that will be passed unmodified to the template
- Returns
Returns the emitted HTML response.
- editSuccess(skel: viur.core.skeleton.SkeletonInstance, tpl: str = None, params: Any = None, *args, **kwargs) str ¶
Renders a page, informing that the entry has been successfully modified.
- Parameters
skel – Skeleton which contains the data of the modified entity
tpl – Name of a different template, which should be used instead of the default one.
params – Optional data that will be passed unmodified to the template
- Returns
Returns the emitted HTML response.
- deleteSuccess(skel: viur.core.skeleton.SkeletonInstance, tpl: str = None, params: Any = None, *args, **kwargs) str ¶
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
skel – Skeleton which contains the data of the deleted entity
params – Optional data that will be passed unmodified to the template
tpl – Name of a different template, which should be used instead of the default one.
- Returns
Returns the emitted HTML response.
- list(skellist: viur.core.skeleton.SkelList, tpl: str = None, params: Any = None, **kwargs) str ¶
Renders a list of entries.
Any data in **kwargs is passed unmodified to the template.
- Parameters
skellist – List of Skeletons with entries to display.
tpl – Name of a different template, which should be used instead of the default one.
params – Optional data that will be passed unmodified to the template
- Returns
Returns the emitted HTML response.
- listRootNodes(repos: List[Dict[Literal[key, name], Any]], tpl: str = None, params: Any = None, **kwargs) str ¶
Renders a list of available repositories.
- Parameters
repos – 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 – Optional data that will be passed unmodified to the template
- Returns
Returns the emitted HTML response.
- Return type
str
- view(skel: viur.core.skeleton.SkeletonInstance, tpl: str = None, params: Any = None, **kwargs) str ¶
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 – Optional data that will be passed unmodified to the template
- Returns
Returns the emitted HTML response.
- listRootNodeContents(subdirs: List, entries: viur.core.skeleton.SkelList, tpl: str = None, params: Any = None, **kwargs) str ¶
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 – List of entries of the current level
tpl – Name of a different template, which should be used instead of the default one
params – Optional data that will be passed unmodified to the template
- Returns
Returns the emitted HTML response.
- addDirSuccess(rootNode: str, path: str, dirname: str, params: Any = None, *args, **kwargs) str ¶
Renders a page, informing that the directory has been successfully created.
- Parameters
rootNode – RootNode-key in which the directory has been created
path – Path in which the directory has been created
dirname – Name of the newly created directory
params – Optional data that will be passed unmodified to the template
- Returns
Returns the emitted HTML response.
- renameSuccess(rootNode: str, path: str, src: str, dest: str, params: Any = None, *args, **kwargs) str ¶
Renders a page, informing that the entry has been successfully renamed.
- Parameters
rootNode – RootNode-key in which the entry has been renamed
path – Path in which the entry has been renamed
src – Old name of the entry
dest – New name of the entry
params – Optional data that will be passed unmodified to the template
- Returns
Returns the emitted HTML response.
- copySuccess(srcrepo: str, srcpath: str, name: str, destrepo: str, destpath: str, type: str, deleteold: str, params: Any = None, *args, **kwargs) str ¶
Renders a page, informing that an entry has been successfully copied/moved.
- Parameters
srcrepo – RootNode-key from which has been copied/moved
srcpath – Path from which the entry has been copied/moved
name – Name of the entry which has been copied/moved
destrepo – RootNode-key to which has been copied/moved
destpath – Path to which the entries has been copied/moved
type – “entry”: Copy/Move an entry, everything else: Copy/Move an directory
deleteold – “0”: Copy, “1”: Move
params – Optional data that will be passed unmodified to the template
- Returns
Returns the emitted HTML response.
- reparentSuccess(obj: viur.core.skeleton.SkeletonInstance, tpl: Optional[str] = None, params: Any = None, **kwargs) str ¶
Renders a page informing that the item was successfully moved.
- Parameters
obj – Skeleton instance of the item that was moved.
tpl – Name of a different template, which should be used instead of the default one
params – Optional data that will be passed unmodified to the template
- Returns
Returns the emitted HTML response.
- setIndexSuccess(obj: viur.core.skeleton.SkeletonInstance, tpl: Optional[str] = None, params: Any = None, *args, **kwargs) str ¶
Renders a page informing that the items sortindex was successfully changed.
- Parameters
obj – Skeleton instance of the item that was changed
tpl – Name of a different template, which should be used instead of the default one
params – Optional data that will be passed unmodified to the template
- Returns
Returns the emitted HTML response.
- cloneSuccess(tpl: str = None, params: Any = None, *args, **kwargs) str ¶
Renders a page informing that the items sortindex was successfully changed.
- Parameters
tpl – Name of a different template, which should be used instead of the default one
params – Optional data that will be passed unmodified to the template
- Returns
Returns the emitted HTML response.
- renderEmail(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() jinja2.Environment ¶
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.