christabor/flask_extras

View on GitHub
flask_extras/macros/extras_msg.html

Summary

Maintainability
Test Coverage
{%- macro alert_type(val) %}
{% set types = ['error', 'warning', 'info', 'success'] %}
{%- if val == 'error' -%}alert-danger{% endif %}
{%- if val == 'warning' -%}alert-warning{% endif %}
{%- if val == 'info' -%}alert-info{% endif %}
{%- if val == 'success' -%}alert-success{% endif %}
{%- if val not in types -%}alert-info{% endif %}
{% endmacro -%}

{%- macro flash_messages(close_btn=True) %}
    {% with messages = get_flashed_messages(with_categories=True) %}
        {% if messages %}
            {% for category, message in messages %}
                <div class="alert {{ alert_type(category) }}">
                    {% if close_btn %}
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">
                            &times;
                        </button>
                    {% endif %}
                    <p class="flash">
                        <strong>{{ category|capitalize }}:</strong>
                        {{ message|safe }}
                    </p>
                </div>
            {% endfor %}
        {% endif %}
    {% endwith %}
{% endmacro -%}