bag.web.flash_msg module

FlashMessage is the natural class to store UI notifications.

Because it knows:

  • the content of a flash message in either plain or rich form(s)
  • the kind (color) of the message, such as info, danger, success etc.
  • different ways of rendering the message on the page
  • whatever else you want (you can add instance variables or subclass it).

This can be used in any web framework. We provide integration for Pyramid in the module bag.web.pyramid.flash_msg.

FlashMessage is able to render itself with Bootstrap styles.

If you are not using Bootstrap, or if you don’t like that I am generating HTML in Python, or if you want some additional content or style, you can still use this class and just render the messages yourself. You can even override the bootstrap_alert property in a subclass.

A more useful version of this module is provided by the state.py module of the kerno library.

class bag.web.flash_msg.FlashMessage(plain=None, rich=None, kind='warning', close=True, allow_duplicate=False)[source]

Bases: object

KINDS = {'danger', 'info', 'success', 'warning'}
bootstrap_alert
to_dict(whitelist=None)[source]

A returns a new dictionary containing all values in this instance.

…or the subset indicated in the whitelist argument.

bag.web.flash_msg.bootstrap_alert(plain=None, rich=None, kind='warning', close=True, v=3)[source]

Render a bootstrap alert message, optionally with a close button.

Provide either plain or rich content. The parameter v can be 3 or 2 depending on your bootstrap version (default 3).