core.render.html.env.viur
¶
Module Contents¶
Functions¶
|
Jinja function for translations |
|
Jinja2 global: Perform an internal Request. |
|
Jinja2 global: Returns the current user from the session, or None if not logged in. |
|
Jinja2 global: Fetch an entry from a given module, and return the data as a dict, |
|
Jinja2 global: Retrieve hostname with protocol. |
|
Jinja2 global: Return the application hash for the current version. This can be used for cache-busting in |
|
Jinja2 global: Return the application version for the current version as set on deployment. |
|
Jinja2 global: Redirect to another URL. |
|
Jinja2 global: Returns the language used for this request. |
|
Jinja2 global: Retrieve name of current module where this renderer is used within. |
|
Jinja2 global: Retrieve path of current module the renderer is used within. |
|
Jinja2 global: Fetches a list of entries which match the given filter criteria. |
|
Jinja2 global: Creates a new ViUR security key. |
|
Jinja2 global: Returns the skeleton structure instead of data for a module. |
|
Jinja2 global: Allows for accessing the request-parameters from the template. |
|
Jinja2 global: Constructs a new URL based on the current requests url. |
|
Jinja2 filter: Format the value in an 'human-readable' file size (i.e. 13 kB, 4.1 MB, 102 Bytes, etc). |
|
Jinja2 filter: Make a shortkey from an entity-key. |
|
|
|
Render an edit-form based on a skeleton. |
|
jinja2 function to get an <img/>-tag for a SVG. |
|
Constructs a signed download-url for the given file-bone. Mostly a wrapper around |
|
Generates a string suitable for use as the srcset tag in html. This functionality provides the browser with a list |
|
Jinja wrapper for File.create_internal_serving_url(), see there for parameter information. |
|
|
|
|
|
Generates a SVG string for a html template |
- core.render.html.env.viur.translate(render, key, default_text=None, hint=None, force_lang=None, **kwargs)¶
Jinja function for translations
See also
core.i18n.TranslationExtension
.- Parameters:
render (core.render.html.default.Render) –
key (str) –
default_text (str) –
hint (str) –
force_lang (str | None) –
- Return type:
str
- core.render.html.env.viur.execRequest(render, path, *args, **kwargs)¶
Jinja2 global: Perform an internal Request.
This function allows to embed the result of another request inside the current template. All optional parameters are passed to the requested resource.
- Parameters:
path (str) – Local part of the url, e.g. user/list. Must not start with an /. Must not include an protocol or hostname.
render (core.render.html.default.Render) –
- Returns:
Whatever the requested resource returns. This is not limited to strings!
- Return type:
Any
- core.render.html.env.viur.getCurrentUser(render)¶
Jinja2 global: Returns the current user from the session, or None if not logged in.
- Returns:
A dict containing user data. Returns None if no user data is available.
- Parameters:
render (core.render.html.default.Render) –
- Return type:
Optional[viur.core.skeleton.SkeletonInstance]
- core.render.html.env.viur.getSkel(render, module, key=None, skel='viewSkel', skel_args=())¶
Jinja2 global: Fetch an entry from a given module, and return the data as a dict, prepared for direct use in the output.
It is possible to specify a different data-model as the one used for rendering (e.g. an editSkel).
- Parameters:
module (str) – Name of the module, from which the data should be fetched.
key (str) – Requested entity-key in an urlsafe-format. If the module is a Singleton
render (core.render.html.default.Render) –
skel (str) –
skel_args (tuple[Any]) –
- Return type:
dict | bool | None
application, the parameter can be omitted. :param skel: Specifies and optionally different data-model :param skel_arg: Optional skeleton arguments to be passed to the skel-function (e.g. for Tree-Modules)
- Returns:
dict on success, False on error.
- Parameters:
render (core.render.html.default.Render) –
module (str) –
key (str) –
skel (str) –
skel_args (tuple[Any]) –
- Return type:
dict | bool | None
- core.render.html.env.viur.getHostUrl(render, forceSSL=False, *args, **kwargs)¶
Jinja2 global: Retrieve hostname with protocol.
- Returns:
Returns the hostname, including the currently used protocol, e.g: http://www.example.com
- Return type:
str
- Parameters:
render (core.render.html.default.Render) –
- core.render.html.env.viur.getVersionHash(render)¶
- Jinja2 global: Return the application hash for the current version. This can be used for cache-busting in
resource links (eg. /static/css/style.css?v={{ getVersionHash() }}. This hash is stable for each version deployed (identical across all instances), but will change whenever a new version is deployed.
- Returns:
The current version hash
- Parameters:
render (core.render.html.default.Render) –
- Return type:
str
- core.render.html.env.viur.getAppVersion(render)¶
Jinja2 global: Return the application version for the current version as set on deployment. :return: The current version
- Parameters:
render (core.render.html.default.Render) –
- Return type:
str
- core.render.html.env.viur.redirect(render, url)¶
Jinja2 global: Redirect to another URL.
- Parameters:
url (str) – URL to redirect to.
render (core.render.html.default.Render) –
- Raises:
viur.core.errors.Redirect
- Return type:
NoReturn
- core.render.html.env.viur.getLanguage(render, resolveAlias=False)¶
Jinja2 global: Returns the language used for this request.
- Parameters:
resolveAlias (bool) – If True, the function tries to resolve the current language using conf.i18n.language_alias_map.
render (core.render.html.default.Render) –
- Return type:
str
- core.render.html.env.viur.moduleName(render)¶
Jinja2 global: Retrieve name of current module where this renderer is used within.
- Returns:
Returns the name of the current module, or empty string if there is no module set.
- Parameters:
render (core.render.html.default.Render) –
- Return type:
str
- core.render.html.env.viur.modulePath(render)¶
Jinja2 global: Retrieve path of current module the renderer is used within.
- Returns:
Returns the path of the current module, or empty string if there is no module set.
- Parameters:
render (core.render.html.default.Render) –
- Return type:
str
- core.render.html.env.viur.getList(render, module, skel='viewSkel', *, skel_args=(), _noEmptyFilter=False, **kwargs)¶
Jinja2 global: Fetches a list of entries which match the given filter criteria.
- Parameters:
render (core.render.html.default.Render) – The html-renderer instance.
module (str) – Name of the module from which list should be fetched.
skel (str) – Name of the skeleton that is used to fetching the list.
skel_arg – Optional skeleton arguments to be passed to the skel-function (e.g. for Tree-Modules)
_noEmptyFilter (bool) – If True, this function will not return any results if at least one parameter is an empty list. This is useful to prevent filtering (e.g. by key) not being performed because the list is empty.
skel_args (tuple[Any]) –
- Returns:
Returns a dict that contains the “skellist” and “cursor” information, or None on error case.
- Return type:
bool | None | list[viur.core.skeleton.SkeletonInstance]
- core.render.html.env.viur.getSecurityKey(render, **kwargs)¶
Jinja2 global: Creates a new ViUR security key.
- Parameters:
render (core.render.html.default.Render) –
- Return type:
str
- core.render.html.env.viur.getStructure(render, module, skel='viewSkel', subSkel=None)¶
Jinja2 global: Returns the skeleton structure instead of data for a module.
- Parameters:
render (core.render.html.default.Render) – The html-renderer instance.
module (str) – Module from which the skeleton is retrieved.
skel (str) – Name of the skeleton.
subSkel (Optional[str]) – If set, return just that subskel instead of the whole skeleton
- Return type:
dict | bool
- core.render.html.env.viur.requestParams(render)¶
Jinja2 global: Allows for accessing the request-parameters from the template.
These returned values are escaped, as users tend to use these in an unsafe manner.
- Returns:
dict of parameter and values.
- Parameters:
render (core.render.html.default.Render) –
- Return type:
dict[str, str]
- core.render.html.env.viur.updateURL(render, **kwargs)¶
Jinja2 global: Constructs a new URL based on the current requests url.
Given parameters are replaced if they exists in the current requests url, otherwise there appended.
- Returns:
Returns a well-formed URL.
- Parameters:
render (core.render.html.default.Render) –
- Return type:
str
- core.render.html.env.viur.fileSize(render, value, binary=False)¶
Jinja2 filter: Format the value in an ‘human-readable’ file size (i.e. 13 kB, 4.1 MB, 102 Bytes, etc). Per default, decimal prefixes are used (Mega, Giga, etc.). When the second parameter is set to True, the binary prefixes are used (Mebi, Gibi).
- Parameters:
render (core.render.html.default.Render) – The html-renderer instance.
value (int | float) – Value to be calculated.
binary (bool) – Decimal prefixes behavior
- Returns:
The formatted file size string in human readable format.
- Return type:
str
- core.render.html.env.viur.shortKey(render, val)¶
Jinja2 filter: Make a shortkey from an entity-key.
- Parameters:
render (core.render.html.default.Render) – The html-renderer instance.
val (str) – Entity-key as string.
- Returns:
Shortkey on success, None on error.
- Return type:
Optional[str]
- core.render.html.env.viur.renderEditBone(render, skel, boneName, boneErrors=None, prefix=None)¶
- Parameters:
render (core.render.html.default.Render) –
- core.render.html.env.viur.renderEditForm(render, skel, ignore=None, hide=None, prefix=None, bones=None)¶
Render an edit-form based on a skeleton.
Render an HTML-form with lables and inputs from the skeleton structure using templates for each bone-types.
- Parameters:
render (core.render.html.default.Render) – The html-renderer instance.
skel (dict) – The skelton which provides the structure.
ignore (list[str]) – Don’t render fields for these bones (name of the bone).
hide (list[str]) – Render these fields as hidden fields (name of the bone).
prefix – Prefix added to the bone names.
bones (list[str]) – If set only the bone with a name in the list would be rendered.
- Returns:
A string containing the HTML-form.
- Return type:
str
- core.render.html.env.viur.embedSvg(render, name, classes=None, **kwargs)¶
jinja2 function to get an <img/>-tag for a SVG. This method will not check the existence of a SVG!
- Parameters:
render (core.render.html.default.Render) – The jinja renderer instance
name (str) – Name of the icon (basename of file)
classes (list[str] | None) – A list of css-classes for the <img/>-tag
kwargs (dict[str, str]) – Further html-attributes for this tag (e.g. “alt” or “title”)
- Returns:
A <img/>-tag
- Return type:
str
- core.render.html.env.viur.downloadUrlFor(render, fileObj, expires=conf.render_html_download_url_expiration, derived=None, downloadFileName=None, language=None)¶
- Constructs a signed download-url for the given file-bone. Mostly a wrapper around
file.File.create_download_url()
.- param render:
The jinja renderer instance
- param fileObj:
The file-bone (eg. skel[“file”])
- param expires:
None if the file is supposed to be public (which causes it to be cached on the google ede caches), otherwise it’s lifetime in seconds.
- param derived:
Optional the filename of a derived file, otherwise the download-link will point to the originally uploaded file.
- param downloadFileName:
The filename to use when saving the response payload locally.
- param language:
Language overwrite if fileObj has multiple languages and we want to explicitly specify one
- return:
THe signed download-url relative to the current domain (eg /download/…)
- Parameters:
render (core.render.html.default.Render) –
fileObj (dict) –
expires (Optional[int]) –
derived (Optional[str]) –
downloadFileName (Optional[str]) –
language (Optional[str]) –
- Return type:
str
- core.render.html.env.viur.srcSetFor(render, fileObj, expires=conf.render_html_download_url_expiration, width=None, height=None, language=None)¶
Generates a string suitable for use as the srcset tag in html. This functionality provides the browser with a list of images in different sizes and allows it to choose the smallest file that will fill it’s viewport without upscaling.
- param render:
The render instance that’s calling this function.
- param fileObj:
The file-bone (or if multiple=True a single value from it) to generate the srcset for.
- param expires:
None if the file is supposed to be public (which causes it to be cached on the google ede caches), otherwise it’s lifetime in seconds.
- param width:
A list of widths that should be included in the srcset. If a given width is not available, it will be skipped.
- param height:
A list of heights that should be included in the srcset. If a given height is not available, it will be skipped.
- param language:
Language overwrite if fileObj has multiple languages and we want to explicitly specify one
- Returns:
The srctag generated or an empty string if a invalid file object was supplied
- Parameters:
render (core.render.html.default.Render) –
fileObj (dict) –
expires (Optional[int]) –
width (Optional[int]) –
height (Optional[int]) –
language (Optional[str]) –
- Return type:
str
- core.render.html.env.viur.serving_url_for(render, *args, **kwargs)¶
Jinja wrapper for File.create_internal_serving_url(), see there for parameter information.
- Parameters:
render (core.render.html.default.Render) –
- core.render.html.env.viur.seoUrlForEntry(render, *args, **kwargs)¶
- Parameters:
render (core.render.html.default.Render) –
- core.render.html.env.viur.seoUrlToFunction(render, *args, **kwargs)¶
- Parameters:
render (core.render.html.default.Render) –
- core.render.html.env.viur.qrcode(render, data)¶
Generates a SVG string for a html template
- Parameters:
data (str) – Any string data that should render to a QR Code.
render (core.render.html.default.Render) –
- Returns:
The SVG string representation.
- Return type:
str