kerno.web.msg_to_html module¶
A registry for ways to convert an UIMessage to HTML code.
- kerno.web.msg_to_html.add_flash(request: kerno.web.pyramid.typing.KRequest, allow_duplicate: bool = False, **kw) kerno.state.UIMessage [source]¶
Add a flash message to the user’s session. For convenience.
- kerno.web.msg_to_html.get_flash_msgs(request: kerno.web.pyramid.typing.KRequest) List[kerno.state.UIMessage] [source]¶
Return the UIMessages currently stored in the HTTP session.
- kerno.web.msg_to_html.msg_to_bootstrap3(flavor: str, msg: kerno.state.UIMessage, close: bool = True)[source]¶
Render the UIMessage
msg
as bootstrap 3 compatible HTML.If using Pyramid you can store UIMessage instances as flash messages in the user’s session, then use this to render them as bootstrap alerts.
- kerno.web.msg_to_html.msg_to_html(flavor, msg, close=True)[source]¶
Render
msg
(an UIMessage instance) as HTML markup.Example usage in a Mako template:
<div class="flash-messages"> % for msg in request.session.get_flash_msgs(): ${msg_to_html(flavor='bootstrap3', msg=msg)|n} % endfor </div>
Example usage in a Jinja2 template:
{%- block flash -%} <div class="flash-messages"> {%- for msg in request.session.get_flash_msgs() -%} {$ msg_to_html(flavor='bootstrap3', msg=msg) | safe $} {%- endfor -%} </div> {%- endblock -%}