Coverage for /home/runner/work/viur-core/viur-core/viur/src/viur/core/render/html/env/session.py: 0%
17 statements
« prev ^ index » next coverage.py v7.6.3, created at 2024-10-16 22:16 +0000
« prev ^ index » next coverage.py v7.6.3, created at 2024-10-16 22:16 +0000
1import typing as t
3from viur.core.render.html.utils import jinjaGlobalFunction
4from viur.core import current
5from ..default import Render
8@jinjaGlobalFunction
9def getSession(render: Render) -> dict:
10 """
11 Jinja2 global: Allows templates to store variables server-side inside the session.
13 Note: This is done in a separated part of the session for security reasons.
15 :returns: A dictionary of session variables.
16 """
17 currSess = current.session.get()
18 if not currSess.get("JinjaSpace"):
19 currSess["JinjaSpace"] = {}
20 return currSess.get("JinjaSpace")
23@jinjaGlobalFunction
24def setSession(render: Render, name: str, value: str) -> None:
25 """
26 Jinja2 global: Allows templates to store variables on server-side inside the session.
28 Note: This is done in a separated part of the session for security reasons.
30 :param render: The html-renderer instance.
31 :param name: Name of the key
32 :param value: Value to store with name.
33 """
34 sessionData = getSession(render)
35 sessionData[name] = value
36 currSess = current.session.get()
37 currSess["JinjaSpace"] = sessionData
38 currSess.markChanged()