~krystianch/buyfriend

c8fbb25a07d52aefb432df776a55b7af2f087a4f — Krystian Chachuła 3 months ago 01dda44
Simplify handling of flashed messages
1 files changed, 17 insertions(+), 15 deletions(-)

M buyfriend/templates/base.html
M buyfriend/templates/base.html => buyfriend/templates/base.html +17 -15
@@ 21,6 21,13 @@
</li>
{%- endmacro %}

{%- macro alert(category, message) %}
{%- set context = {'error': 'danger'}.get(category, category) %}
<div class="alert{% if context %} alert-{{ context }}{% endif %}" role="alert">
  {{ message | safe }}
</div>
{%- endmacro %}

{%- block body %}

<div class="container">


@@ 57,23 64,18 @@
    </div>
  </nav>

  {%- set messages = get_flashed_messages(with_categories=true) %}
  {%- if messages or config.MESSAGES.message[1] %}

  <div>
  {%- for category, message in messages %}
    {%- set context = {'error': 'danger'}.get(category, category) %}
    <div class="alert alert-{{ context }}" role="alert">
      {{ message }}
    </div>
  <div id=alerts>
  {%- for category, message in get_flashed_messages(with_categories=true) %}
  {%- filter indent(4) %}
  {{- alert(category, message) }}
  {%- endfilter %}
  {%- endfor %}
  {%- set category, message = config.MESSAGES.message %}
  {%- set context = {'error': 'danger'}.get(category, category) %}
    <div class="alert alert-{{ context }}" role="alert">
      {{ message | safe }}
    </div>
  </div>
  {%- if config.MESSAGES.message[1] %}
  {%- filter indent(4) %}
  {{- alert(*config.MESSAGES.message) }}
  {%- endfilter %}
  {%- endif %}
  </div>

  {%- filter indent(2) %}
  {% block content %}{% endblock %}