Session storage

Bindings

Sometimes it is useful to save some of user states between sessions:

  • Form values

  • Table sort orders

  • Visual design options

  • Last opened page

  • Etc

pantra introduces session storage:

digraph "Session storage" { size="4,4"; UI [label="UI data\nor local state"]; Dict [label="Data mapping\n+key", shape=rect]; Rec [label="Named\nbinding", shape=rect] Storage; UI -> Dict -> Rec -> Storage [dir=both]; }

Classes

Default implementation is set by parameter `

class pantra.session_storage.SessionStorage(session: Session)[source]

Abstract session storage.

Allows to keep user values between sessions.

Parameters:

session (Session)

add_binding(name: str, dict_ref: dict[str, Any], key: str)[source]

Bind storage record to the specific key of the dictionary

Parameters:
  • name (str) – The name of the record

  • dict_ref (dict[str, Any]) – The dictionary to bind

  • key (str) – The key (of dict_ref) to bind

gather()[source]

Gather all bound values from dictionaries to set session state

distribute()[source]

Distribute values from session state to bound dictionaries

reload()[source]

Reload session state

sync()[source]

Sync session state

class pantra.session_storage.NullSessionStorage(session: Session)[source]

Default session storage behavior - just keep in session state

Parameters:

session (Session)

class pantra.session_storage.ShelveSessionStorage(session: Session)[source]

Use shelve to keep user data

Parameters:

session (Session)