websauna.system.core.messages module

class websauna.system.core.messages.FlashMessage(plain=None, rich=None, kind='warning', msg_id=None, extra=None)[source]

Bases: object

Internal storage format of flash message.

KINDS = {'error', 'info', 'success', 'warning'}

Allows session storage to know if this message has been already added.

websauna.system.core.messages.add(request, msg, kind='info', msg_id=None, extra=None, html=False, allow_duplicates=False)[source]

Add a message which is shown to the user on the next page load.

This is so called Flash message. The message is stored in the session. On the next page load, the HTML templates and framework must read all pending messages from the session store and display them to the user. Usually this is a notification rendered at the top of the page.

Duplicate messages are discarded based on msg_id unless allow_duplicates is set.

Messages are stored in the session queue, keyed by the message kind.

  • msg (str) – Message as a string

  • kind (str) – One of ‘error’, ‘warning’, ‘info’, ‘success’. Defaults to ‘info’

  • msg_id (Optional[str]) – CSS id set on the alert box. Useful for functional testing.

  • html – The message is HTML

  • extra (Optional[dict]) – Dictionary of application specific extra parameters or None. The content must be pickable.

  • allow_duplicates – Allow duplicate messages

websauna.system.core.messages.clear(request, kinds=('info', 'error', 'warning', 'success'))[source]

Clear all messages from the flash message queue.