core.render.html.env.viur

Module Contents

Functions

translate(→ str)

execRequest(→ Any)

Jinja2 global: Perform an internal Request.

getCurrentUser(...)

Jinja2 global: Returns the current user from the session, or None if not logged in.

getSkel(→ Union[dict, bool, None])

Jinja2 global: Fetch an entry from a given module, and return the data as a dict,

getHostUrl(render[, forceSSL])

Jinja2 global: Retrieve hostname with protocol.

getVersionHash(→ str)

Jinja2 global: Return the application hash for the current version. This can be used for cache-busting in

getAppVersion(→ str)

Jinja2 global: Return the application version for the current version as set on deployment.

redirect(→ NoReturn)

Jinja2 global: Redirect to another URL.

getLanguage(→ str)

Jinja2 global: Returns the language used for this request.

moduleName(→ str)

Jinja2 global: Retrieve name of current module where this renderer is used within.

modulePath(→ str)

Jinja2 global: Retrieve path of current module the renderer is used within.

getList(→ Union[bool, None, ...)

Jinja2 global: Fetches a list of entries which match the given filter criteria.

getSecurityKey(→ str)

Jinja2 global: Creates a new ViUR security key.

getStructure(→ Union[Dict, bool])

Jinja2 global: Returns the skeleton structure instead of data for a module.

requestParams(→ Dict[str, str])

Jinja2 global: Allows for accessing the request-parameters from the template.

updateURL(→ str)

Jinja2 global: Constructs a new URL based on the current requests url.

fileSize(→ str)

Jinja2 filter: Format the value in an 'human-readable' file size (i.e. 13 kB, 4.1 MB, 102 Bytes, etc).

urlencode(→ str)

Jinja2 filter: Make a string URL-safe.

shortKey(→ Optional[str])

Jinja2 filter: Make a shortkey from an entity-key.

renderEditBone(render, skel, boneName[, boneErrors, ...])

renderEditForm(→ str)

Render an edit-form based on a skeleton.

embedSvg(→ str)

jinja2 function to get an <img/>-tag for a SVG.

downloadUrlFor(→ Optional[str])

Constructs a signed download-url for the given file-bone. Mostly a wrapper around

srcSetFor(→ str)

Generates a string suitable for use as the srcset tag in html. This functionality provides the browser

seoUrlForEntry(render, *args, **kwargs)

seoUrlToFunction(render, *args, **kwargs)

core.render.html.env.viur.translate(render: core.render.html.default.Render, key: str, **kwargs) str
core.render.html.env.viur.execRequest(render: core.render.html.default.Render, path: str, *args, **kwargs) Any

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 – Local part of the url, e.g. user/list. Must not start with an /. Must not include an protocol or hostname.

Returns

Whatever the requested resource returns. This is not limited to strings!

core.render.html.env.viur.getCurrentUser(render: core.render.html.default.Render) Optional[viur.core.skeleton.SkeletonInstance]

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.

core.render.html.env.viur.getSkel(render: core.render.html.default.Render, module: str, key: str = None, skel: str = 'viewSkel') Union[dict, bool, None]

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 – Name of the module, from which the data should be fetched.

  • key – Requested entity-key in an urlsafe-format. If the module is a Singleton

application, the parameter can be omitted. :param skel: Specifies and optionally different data-model

Returns

dict on success, False on error.

core.render.html.env.viur.getHostUrl(render: core.render.html.default.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

core.render.html.env.viur.getVersionHash(render: core.render.html.default.Render) str
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

core.render.html.env.viur.getAppVersion(render: core.render.html.default.Render) str

Jinja2 global: Return the application version for the current version as set on deployment. :return: The current version

core.render.html.env.viur.redirect(render: core.render.html.default.Render, url: str) NoReturn

Jinja2 global: Redirect to another URL.

Parameters

url – URL to redirect to.

Raises

viur.core.errors.Redirect

core.render.html.env.viur.getLanguage(render: core.render.html.default.Render, resolveAlias: bool = False) str

Jinja2 global: Returns the language used for this request.

Parameters

resolveAlias – If True, the function tries to resolve the current language using conf[“viur.languageAliasMap”].

core.render.html.env.viur.moduleName(render: core.render.html.default.Render) str

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.

core.render.html.env.viur.modulePath(render: core.render.html.default.Render) str

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.

core.render.html.env.viur.getList(render: core.render.html.default.Render, module: str, skel: str = 'viewSkel', _noEmptyFilter: bool = False, *args, **kwargs) Union[bool, None, List[viur.core.skeleton.SkeletonInstance]]

Jinja2 global: Fetches a list of entries which match the given filter criteria.

Parameters
  • render – The html-renderer instance.

  • module – Name of the module from which list should be fetched.

  • skel – Name of the skeleton that is used to fetching the list.

  • _noEmptyFilter – 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.

Returns

Returns a dict that contains the “skellist” and “cursor” information, or None on error case.

core.render.html.env.viur.getSecurityKey(render: core.render.html.default.Render, **kwargs) str

Jinja2 global: Creates a new ViUR security key.

core.render.html.env.viur.getStructure(render: core.render.html.default.Render, module: str, skel: str = 'viewSkel', subSkel: Optional[str] = None) Union[Dict, bool]

Jinja2 global: Returns the skeleton structure instead of data for a module.

Parameters
  • render – The html-renderer instance.

  • module – Module from which the skeleton is retrieved.

  • skel – Name of the skeleton.

  • subSkel – If set, return just that subskel instead of the whole skeleton

core.render.html.env.viur.requestParams(render: core.render.html.default.Render) Dict[str, str]

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.

core.render.html.env.viur.updateURL(render: core.render.html.default.Render, **kwargs) str

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.

core.render.html.env.viur.fileSize(render: core.render.html.default.Render, value: Union[int, float], binary: bool = False) str

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 – The html-renderer instance.

  • value – Value to be calculated.

  • binary – Decimal prefixes behavior

Returns

The formatted file size string in human readable format.

core.render.html.env.viur.urlencode(render: core.render.html.default.Render, val: str) str

Jinja2 filter: Make a string URL-safe.

Parameters
  • render – The html-renderer instance.

  • val – String to be quoted.

Returns

Quoted string.

core.render.html.env.viur.shortKey(render: core.render.html.default.Render, val: str) Optional[str]

Jinja2 filter: Make a shortkey from an entity-key.

Parameters
  • render – The html-renderer instance.

  • val – Entity-key as string.

Returns

Shortkey on success, None on error.

core.render.html.env.viur.renderEditBone(render: core.render.html.default.Render, skel, boneName, boneErrors=None, prefix=None)
core.render.html.env.viur.renderEditForm(render: core.render.html.default.Render, skel: Dict, ignore: List[str] = None, hide: List[str] = None, prefix=None) str

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 – The html-renderer instance.

  • skel – The skelton which provides the structure.

  • ignore – Don’t render fields for these bones (name of the bone).

  • hide – Render these fields as hidden fields (name of the bone).

  • prefix – Prefix added to the bone names.

Returns

A string containing the HTML-form.

core.render.html.env.viur.embedSvg(render: core.render.html.default.Render, name: str, classes: Union[List[str], None] = None, **kwargs: Dict[str, str]) str

jinja2 function to get an <img/>-tag for a SVG. This method will not check the existence of a SVG!

Parameters
  • render – The jinja renderer instance

  • name – Name of the icon (basename of file)

  • classes – A list of css-classes for the <img/>-tag

  • kwargs – Further html-attributes for this tag (e.g. “alt” or “title”)

Returns

A <img/>-tag

core.render.html.env.viur.downloadUrlFor(render: core.render.html.default.Render, fileObj: dict, expires: Union[None, int] = conf['viur.downloadUrlFor.expiration'], derived: Optional[str] = None, downloadFileName: Optional[str] = None) Optional[str]

Constructs a signed download-url for the given file-bone. Mostly a wrapper around viur.core.utils.downloadUrlFor().

Parameters
  • render – The jinja renderer instance

  • fileObj – The file-bone (eg. skel[“file”])

  • 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

  • derived – Optional the filename of a derived file, otherwise the download-link will point to the originally uploaded file.

  • downloadFileName – The filename to use when saving the response payload locally.

Returns

THe signed download-url relative to the current domain (eg /download/…)

core.render.html.env.viur.srcSetFor(render: core.render.html.default.Render, fileObj: dict, expires: Optional[int], width: Optional[int] = None, height: Optional[int] = None) str

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

Parameters
  • width – A list of widths that should be included in the srcset. If a given width is not available, it will be skipped.

  • height – A list of heights that should be included in the srcset. If a given height is not available, it will be skipped.

Returns

The srctag generated or an empty string if a invalid file object was supplied

core.render.html.env.viur.seoUrlForEntry(render: core.render.html.default.Render, *args, **kwargs)
core.render.html.env.viur.seoUrlToFunction(render: core.render.html.default.Render, *args, **kwargs)