core.render.html
¶
Subpackages¶
Submodules¶
Package Contents¶
Classes¶
The core jinja2 render. |
|
Functions¶
|
Function for activating extensions in Jinja2. |
Decorator, marks a function as a Jinja2 filter. |
|
Decorator, marks a function as a Jinja2 global. |
|
|
Decorator, marks a function as a Jinja2 test. |
- 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() a skellist is provided containing all requested skeletons to a limit
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'¶
- __haveEnvImported_ = False¶
- getTemplateFileName(template, ignoreStyle=False, raise_exception=True)¶
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 (str | list[str] | tuple[str]) – The basename of the template to use. This can optionally be also a sequence of names.
ignoreStyle (bool) – Ignore any maybe given style hints.
raise_exception (bool) – Defaults to raise an exception when not found, otherwise returns None.
- Returns:
Filename of the template
- Return type:
str | None
- 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).
- Return type:
jinja2.ChoiceLoader
- renderBoneValue(bone, skel, key, boneValue, isLanguageWrapped=False)¶
Renders the value of a bone.
It can be overridden and super-called from a custom renderer.
- Parameters:
bone (viur.core.bones.BaseBone) – The bone which value should be rendered. (inherited from
viur.core.bones.base.BaseBone
).skel (viur.core.skeleton.SkeletonInstance) – The skeleton containing the bone instance.
key (Any) – The name of the bone.
boneValue (Any) – The value of the bone.
isLanguageWrapped (bool) – Is this bone wrapped inside a
LanguageWrapper
?
- Returns:
A dict containing the rendered attributes.
- Return type:
list | dict | KeyValueWrapper | viur.core.i18n.LanguageWrapper | str | None
- get_template(action, template)¶
Internal function for retrieving a template from an action name.
- Parameters:
action (str) –
template (str) –
- Return type:
jinja2.Template
- render_action_template(default, skel, action, tpl=None, params=None, **kwargs)¶
Internal action rendering that provides a variable structure to render an input-form. The required information is passed via skel[“structure”], skel[“value”] and skel[“errors”].
Any data in **kwargs is passed unmodified to the template.
- Parameters:
default (str) – The default action to render, which is used to construct a template name.
skel (viur.core.skeleton.SkeletonInstance) – Skeleton of which should be used for the action.
action (str) – The name of the action, which is passed into the template.
tpl (str) – Name of a different template, which should be used instead of the default one.
params (dict) – Optional data that will be passed unmodified to the template.
- Return type:
str
Any data in **kwargs is passed unmodified to the template.
- Returns:
Returns the emitted HTML response.
- Parameters:
default (str) –
skel (viur.core.skeleton.SkeletonInstance) –
action (str) –
tpl (str) –
params (dict) –
- Return type:
str
- render_view_template(default, skel, action, tpl=None, params=None, **kwargs)¶
Renders a page with an entry.
- Parameters:
default (str) – The default action to render, which is used to construct a template name.
skel (viur.core.skeleton.SkeletonInstance) – Skeleton which contains the data of the corresponding entity.
action (str) – The name of the action, which is passed into the template.
tpl (str) – Name of a different template, which should be used instead of the default one.
params (dict) – Optional data that will be passed unmodified to the template
- Return type:
str
Any data in **kwargs is passed unmodified to the template.
- Returns:
Returns the emitted HTML response.
- Parameters:
default (str) –
skel (viur.core.skeleton.SkeletonInstance) –
action (str) –
tpl (str) –
params (dict) –
- Return type:
str
- list(skellist, action='list', tpl=None, params=None, **kwargs)¶
Renders a page with a list of entries.
- Parameters:
skellist (viur.core.skeleton.SkelList) – List of Skeletons with entries to display.
action (str) – The name of the action, which is passed into the template.
tpl (str) – Name of a different template, which should be used instead of the default one.
params (Any) – Optional data that will be passed unmodified to the template
- Return type:
str
Any data in **kwargs is passed unmodified to the template.
- Returns:
Returns the emitted HTML response.
- Parameters:
skellist (viur.core.skeleton.SkelList) –
action (str) –
tpl (str) –
params (Any) –
- Return type:
str
- view(skel, action='view', tpl=None, params=None, **kwargs)¶
Renders a page for viewing an entry.
For details, see self.render_view_template().
- Parameters:
skel (viur.core.skeleton.SkeletonInstance) –
action (str) –
tpl (str) –
params (Any) –
- Return type:
str
- add(skel, action='add', tpl=None, params=None, **kwargs)¶
Renders a page for adding an entry.
For details, see self.render_action_template().
- Parameters:
skel (viur.core.skeleton.SkeletonInstance) –
action (str) –
tpl (str) –
params (Any) –
- Return type:
str
- edit(skel, action='edit', tpl=None, params=None, **kwargs)¶
Renders a page for modifying an entry.
For details, see self.render_action_template().
- Parameters:
skel (viur.core.skeleton.SkeletonInstance) –
action (str) –
tpl (str) –
params (Any) –
- Return type:
str
- addSuccess(skel, action='addSuccess', tpl=None, params=None, **kwargs)¶
Renders a page, informing that an entry has been successfully created.
For details, see self.render_view_template().
- Parameters:
skel (viur.core.skeleton.SkeletonInstance) –
action (str) –
tpl (str) –
params (Any) –
- Return type:
str
- editSuccess(skel, action='editSuccess', tpl=None, params=None, **kwargs)¶
Renders a page, informing that an entry has been successfully modified.
For details, see self.render_view_template().
- Parameters:
skel (viur.core.skeleton.SkeletonInstance) –
action (str) –
tpl (str) –
params (Any) –
- Return type:
str
- deleteSuccess(skel, action='deleteSuccess', tpl=None, params=None, **kwargs)¶
Renders a page, informing that an entry has been successfully deleted.
For details, see self.render_view_template().
- Parameters:
skel (viur.core.skeleton.SkeletonInstance) –
action (str) –
tpl (str) –
params (Any) –
- Return type:
str
- listRootNodes(repos, action='listrootnodes', tpl=None, params=None, **kwargs)¶
Renders a list of available root nodes.
- Parameters:
repos (List[dict[Literal[key, name], Any]]) – List of repositories (dict with “key”=>Repo-Key and “name”=>Repo-Name)
action (str) – The name of the action, which is passed into the template.
tpl (str) – Name of a different template, which should be used instead of the default one.
params (Any) – Optional data that will be passed unmodified to the template
- Return type:
str
Any data in **kwargs is passed unmodified to the template.
- Returns:
Returns the emitted HTML response.
- Parameters:
repos (List[dict[Literal[key, name], Any]]) –
action (str) –
tpl (str) –
params (Any) –
- Return type:
str
- renderEmail(dests, file=None, template=None, skel=None, **kwargs)¶
Renders an email. Uses the first not-empty line as subject and the remaining template as body.
- Parameters:
dests (List[str]) – Destination recipients.
file (str) – The name of a template from the deploy/emails directory.
template (str) – This string is interpreted as the template contents. Alternative to load from template file.
skel (None | dict | viur.core.skeleton.SkeletonInstance | List[viur.core.skeleton.SkeletonInstance]) – Skeleton or dict which data to supply to the template.
- Returns:
Returns the rendered email subject and body.
- Return type:
tuple[str, str]
- getEnv()¶
Constructs 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() a skellist is provided containing all requested skeletons to a limit
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'¶
- second_factor_add_template = 'user_secondfactor_add'¶
- second_factor_add_success_template = 'user_secondfactor_add_success'¶
- second_factor_choice_template = 'user_second_factor_choice'¶
- _choose_template(tpl, fallback_attribute)¶
- Parameters:
tpl (None | str) –
fallback_attribute (str) –
- Return type:
str
- login_disabled(authMethods, tpl=None, **kwargs)¶
- Parameters:
tpl (str | None) –
- login(skel, tpl=None, **kwargs)¶
- Parameters:
tpl (str | None) –
- loginChoices(authMethods, tpl=None, **kwargs)¶
- Parameters:
tpl (str | None) –
- loginSucceeded(tpl=None, **kwargs)¶
- Parameters:
tpl (str | None) –
- logoutSuccess(tpl=None, **kwargs)¶
- Parameters:
tpl (str | None) –
- verifySuccess(skel, tpl=None, **kwargs)¶
- Parameters:
tpl (str | None) –
- verifyFailed(tpl=None, **kwargs)¶
- Parameters:
tpl (str | None) –
- passwdRecoverInfo(msg, skel=None, tpl=None, **kwargs)¶
- Parameters:
tpl (str | None) –
- passwdRecover(*args, **kwargs)¶
- second_factor_add(action_name, name, add_url, tpl, otp_uri=None)¶
- Parameters:
action_name (str) –
name (str) –
add_url (str) –
tpl (str | None) –
- second_factor_add_success(action_name, name, tpl=None)¶
- Parameters:
action_name (str) –
name (str) –
tpl (str | None) –
- second_factor_choice(second_factors, tpl=None)¶
- Parameters:
second_factors (Iterable[viur.core.modules.user.UserSecondFactorAuthentication]) –
tpl (str | None) –
- core.render.html.jinjaGlobalExtension(ext)¶
Function for activating extensions in Jinja2.
- core.render.html.jinjaGlobalFilter(f)¶
Decorator, marks a function as a Jinja2 filter.
- core.render.html.jinjaGlobalFunction(f)¶
Decorator, marks a function as a Jinja2 global.
- core.render.html.jinjaGlobalTest(func_or_alias)¶
Decorator, marks a function as a Jinja2 test.
To avoid name conflicts you can call the decorator with an alias as first argument. Otherwise, the test will be registered under the function name.
# Example: from viur.core.render.html import jinjaGlobalTest # @jinjaGlobalTest # available under "positive_number" @jinjaGlobalTest("positive") # available under "positive" def positive_number(render, value): return isinstance(value, int) and value > 0
- Parameters:
func_or_alias (Callable | str) –
- Return type:
Callable