core.render.html
¶
Subpackages¶
Submodules¶
Package Contents¶
Classes¶
The core jinja2 render. |
|
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: 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.
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.
- get_template(action: str, template: str) jinja2.Template ¶
Internal function for retrieving a template from an action name.
- render_action_template(default: str, skel: viur.core.skeleton.SkeletonInstance, action: str, tpl: str = None, params: Dict = None, **kwargs) str ¶
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 – The default action to render, which is used to construct a template name.
skel – Skeleton of which should be used for the action.
action – The name of the action, which is passed into the template.
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.
Any data in **kwargs is passed unmodified to the template.
- Returns
Returns the emitted HTML response.
- render_view_template(default: str, skel: viur.core.skeleton.SkeletonInstance, action: str, tpl: str = None, params: Dict = None, **kwargs) str ¶
Renders a page with an entry.
- Parameters
default – The default action to render, which is used to construct a template name.
skel – Skeleton which contains the data of the corresponding entity.
action – The name of the action, which is passed into the template.
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
Any data in **kwargs is passed unmodified to the template.
- Returns
Returns the emitted HTML response.
- list(skellist: viur.core.skeleton.SkelList, action: str = 'list', tpl: str = None, params: Any = None, **kwargs) str ¶
Renders a page with a list of entries.
- Parameters
skellist – List of Skeletons with entries to display.
action – The name of the action, which is passed into the template.
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
Any data in **kwargs is passed unmodified to the template.
- Returns
Returns the emitted HTML response.
- view(skel: viur.core.skeleton.SkeletonInstance, action: str = 'view', tpl: str = None, params: Any = None, **kwargs) str ¶
Renders a page for viewing an entry.
For details, see self.render_view_template().
- add(skel: viur.core.skeleton.SkeletonInstance, action: str = 'add', tpl: str = None, params: Any = None, **kwargs) str ¶
Renders a page for adding an entry.
For details, see self.render_action_template().
- edit(skel: viur.core.skeleton.SkeletonInstance, action: str = 'edit', tpl: str = None, params: Any = None, **kwargs) str ¶
Renders a page for modifying an entry.
For details, see self.render_action_template().
- addSuccess(skel: viur.core.skeleton.SkeletonInstance, action: str = 'addSuccess', tpl: str = None, params: Any = None, **kwargs) str ¶
Renders a page, informing that an entry has been successfully created.
For details, see self.render_view_template().
- editSuccess(skel: viur.core.skeleton.SkeletonInstance, action: str = 'editSuccess', tpl: str = None, params: Any = None, **kwargs) str ¶
Renders a page, informing that an entry has been successfully modified.
For details, see self.render_view_template().
- deleteSuccess(skel: viur.core.skeleton.SkeletonInstance, action: str = 'deleteSuccess', tpl: str = None, params: Any = None, **kwargs) str ¶
Renders a page, informing that an entry has been successfully deleted.
For details, see self.render_view_template().
- listRootNodes(repos: List[Dict[Literal[key, name], Any]], action: str = 'listrootnodes', tpl: str = None, params: Any = None, **kwargs) str ¶
Renders a list of available root nodes.
- Parameters
repos – List of repositories (dict with “key”=>Repo-Key and “name”=>Repo-Name)
action – The name of the action, which is passed into the template.
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
Any data in **kwargs is 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 ¶
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.
- 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¶
- login_disabled(authMethods, tpl=None, **kwargs)¶
- login(skel, tpl=None, **kwargs)¶
- loginChoices(authMethods, tpl=None, **kwargs)¶
- loginSucceeded(tpl=None, **kwargs)¶
- logoutSuccess(tpl=None, **kwargs)¶
- verifySuccess(skel, tpl=None, **kwargs)¶
- verifyFailed(tpl=None, **kwargs)¶
- passwdRecoverInfo(msg, skel=None, tpl=None, **kwargs)¶
- passwdRecover(*args, **kwargs)¶
- 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: Union[Callable, str]) Callable ¶
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