kerno.state module

Classes that store outgoing state.

These are typically returned by action layer code to controllers.

exception kerno.state.MalbonaRezulto(status_int: int = 400, title: str = '', plain: str = '', html: str = '', level: str = 'danger', invalid: Optional[Dict[str, Any]] = None, **kw)[source]

Bases: kerno.state.Returnable, Exception

Base class for exceptions raised by actions.

level = 'danger'
status_int = 400
class kerno.state.Returnable(commands: Optional[List[kerno.state.UICommand]] = None, debug: Optional[Dict[str, Any]] = None, redirect: str = '', **kw)[source]

Bases: object

Base class for Rezulto and for MalbonaRezulto.

Returnable is the base class for what Actions should return. It contains:

  • messages: Grave UI messages.

  • toasts: UI messages that disappear automatically after a while.

  • commands: messages to the UI, e. g., add an entity to your models

  • debug: A dict with information that is not displayed to the end user.

  • redirect: URL or screen to redirect to.

Subclasses overload the status_int and level static variables.

add_command(**kw) kerno.state.UICommand[source]

Add to the commands for the UI to perform.

add_message(level: str = '', **kw) kerno.state.UIMessage[source]

Add to the grave messages to be displayed to the user on the UI.

add_toast(level: str = '', **kw) kerno.state.UIMessage[source]

Add to the quick messages to be displayed to the user on the UI.

level = 'danger'
status_int = 500
class kerno.state.Rezulto(commands: Optional[List[kerno.state.UICommand]] = None, debug: Optional[Dict[str, Any]] = None, redirect: str = '', **kw)[source]

Bases: kerno.state.Returnable

Well-organized successful response object.

When your action succeeds you should return a Rezulto. Unsuccessful operations raise MalbonaRezulto instead.

level = 'success'
status_int = 200
class kerno.state.UICommand(name: str, payload: Dict[str, Any])[source]

Bases: object

Represents a message telling the UI to do something.

name
payload
class kerno.state.UIMessage(level: str = 'danger', title: str = '', plain: str = '', html: str = '')[source]

Bases: object

Represents a message to be displayed to the user in the UI.

LEVELS = ['danger', 'warning', 'info', 'success']
classmethod from_payload(payload: Union[str, Dict[str, Any]]) kerno.state.UIMessage[source]
to_dict() Dict[str, Any][source]
kerno.state.malbona_to_dict(obj: kerno.state.MalbonaRezulto, flavor: str = '', **kw) Dict[str, Any][source]

Convert a MalbonaRezulto to a dictionary.

kerno.state.returnable_to_dict(obj, flavor='', **kw)[source]

Convert instance to a dictionary, usually for JSON output.

kerno.state.uicommand_to_dict(obj: kerno.state.UICommand, flavor: str = '', **kw) collections.OrderedDict[str, Any][source]

Convert to dict a UICommand instance.