Browse Source

flash messages allow a dismissable parameter

php2python
Holger Frey 7 years ago
parent
commit
6f334852eb
  1. 6
      ordr2/templates/macros.jinja2
  2. 6
      ordr2/views/__init__.py
  3. 9
      ordr2/views/account.py

6
ordr2/templates/macros.jinja2

@ -2,8 +2,10 @@
{% for queue in ('success', 'info', 'warning', 'error') %} {% for queue in ('success', 'info', 'warning', 'error') %}
{% for message in request.session.pop_flash(queue) %} {% for message in request.session.pop_flash(queue) %}
{% set css_class = 'danger' if queue == 'error' else queue %} {% set css_class = 'danger' if queue == 'error' else queue %}
<div class="alert alert-{{ css_class }} alert-dismissible" role="alert"> <div class="alert alert-{{ css_class }} {% if message.dismissable %}alert-dismissible{% endif %}" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button> {% if message.dismissable %}
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
{% endif %}
<strong>{{message.message|safe}}</strong> <strong>{{message.message|safe}}</strong>
{% if message.description %} {% if message.description %}
<br>{{message.description|safe}} <br>{{message.description|safe}}

6
ordr2/views/__init__.py

@ -1,12 +1,12 @@
from collections import namedtuple from collections import namedtuple
FlashMessage = namedtuple('FlashMessage', 'message description') FlashMessage = namedtuple('FlashMessage', 'message description dismissable')
def flash(request, channel, message, description=''): def flash(request, channel, message, description='', dismissable=True):
''' small wrapper around request.session.flash ''' ''' small wrapper around request.session.flash '''
msg = FlashMessage(message=message, description=description) msg = FlashMessage(message, description, dismissable)
request.session.flash(msg, channel, allow_duplicate=False) request.session.flash(msg, channel, allow_duplicate=False)

9
ordr2/views/account.py

@ -39,7 +39,14 @@ def login(context, request):
headers=headers headers=headers
) )
#request.session.flash(MSG_LOGIN_ERROR.format(url), 'error') request.flash(
'error',
'Oh snap! You entered the wrong unsername and/or password.',
'''Please try it again. If you still can not log in make sure that
your account is activated and you haven't enabled caps lock on
your keyboard.''',
dismissable=False
)
return HTTPFound(request.resource_path(context, 'login')) return HTTPFound(request.resource_path(context, 'login'))