Browse Source

moved display of flash messages to template macros

master
Holger Frey 7 years ago
parent
commit
511e5d0c25
  1. 31
      ordr2/events.py
  2. 3
      ordr2/templates/account/forgot_password_email.jinja2
  3. 3
      ordr2/templates/account/forgot_password_form.jinja2
  4. 5
      ordr2/templates/account/login.jinja2
  5. 3
      ordr2/templates/account/registration_completed.jinja2
  6. 3
      ordr2/templates/account/registration_confirmation.jinja2
  7. 9
      ordr2/templates/layout.jinja2
  8. 11
      ordr2/templates/macros.jinja2

31
ordr2/events.py

@ -29,16 +29,11 @@ class UserNotification(object): @@ -29,16 +29,11 @@ class UserNotification(object):
#: template to render
template = None
def __init__(self, request, account, data=None):
def __init__(self, request, account, data=None, send_to=None):
self.request = request
self.account = account
self.data = data
class CompleteRegistration(UserNotification):
''' user notification for account activation '''
subject = '[ordr] Please verify your email address'
template = 'ordr2:templates/emails/registration.jinja2'
self.send_to = send_to or account.email
class AccountActivation(UserNotification):
@ -47,10 +42,16 @@ class AccountActivation(UserNotification): @@ -47,10 +42,16 @@ class AccountActivation(UserNotification):
template = 'ordr2:templates/emails/activation.jinja2'
class PasswordReset(UserNotification):
''' user notification for password reset link '''
subject = '[ordr] Password Reset'
template = 'ordr2:templates/emails/password_reset.jinja2'
class ChangedEmail(UserNotification):
''' user notification for a changed email address '''
subject = '[ordr] Please verify your email address'
template = 'ordr2:templates/emails/mail_change.jinja2'
class CompleteRegistration(UserNotification):
''' user notification for account activation '''
subject = '[ordr] Please verify your email address'
template = 'ordr2:templates/emails/registration.jinja2'
class OrderStatusChange(UserNotification):
@ -59,6 +60,12 @@ class OrderStatusChange(UserNotification): @@ -59,6 +60,12 @@ class OrderStatusChange(UserNotification):
template = 'ordr2:templates/emails/order.jinja2'
class PasswordReset(UserNotification):
''' user notification for password reset link '''
subject = '[ordr] Password Reset'
template = 'ordr2:templates/emails/password_reset.jinja2'
# subsribers for events
@subscriber(UserNotification)
@ -72,7 +79,7 @@ def notify_user(event): @@ -72,7 +79,7 @@ def notify_user(event):
message = Message(
subject=event.subject,
sender=event.request.registry.settings['mail.default_sender'],
recipients=[event.account.email],
recipients=[event.send_to],
html=body
)
mailer = get_mailer(event.request.registry)

3
ordr2/templates/account/forgot_password_email.jinja2

@ -4,6 +4,9 @@ @@ -4,6 +4,9 @@
{% block content %}
<h1>Password Reset Link</h1>
{{ macros.show_flash_messages() }}
<p>To reset your password, an email has been sent to you.</p>
<p>Please follow the link in the email to set a new password.</p>

3
ordr2/templates/account/forgot_password_form.jinja2

@ -4,6 +4,9 @@ @@ -4,6 +4,9 @@
{% block content %}
<h1>Forgotten password?</h1>
{{ macros.show_flash_messages() }}
<form action="{{ request.resource_url(request.root, 'account', 'forgot-password') }}" method="POST" id="forgotten-password-form" class="form">
<input type="hidden" name="csrf_token" value="{{ get_csrf_token() }}">
<div class="form-group">

5
ordr2/templates/account/login.jinja2

@ -3,8 +3,9 @@ @@ -3,8 +3,9 @@
{% block title %} Ordr | Login Failed {% endblock title %}
{% block content %}
<h1>Try again…</h1>
<p class="alert alert-danger">You entered the wrong username or password.</p>
<h1>Log In</h1>
{{ macros.show_flash_messages() }}
<form action="{{ request.resource_url(request.root, 'account', 'login') }}" method="POST" id="login-form">
<input type="hidden" name="csrf_token" value="{{ get_csrf_token() }}">

3
ordr2/templates/account/registration_completed.jinja2

@ -4,6 +4,9 @@ @@ -4,6 +4,9 @@
{% block content %}
<h1>Account Registration Completed</h1>
{{ macros.show_flash_messages() }}
<p>Thank you for verifying your email address.</p>
<p>Before you can start ordering, an administrator must activate your account</p>
<p>You'll receive an email when your account is activated</p>

3
ordr2/templates/account/registration_confirmation.jinja2

@ -5,6 +5,9 @@ @@ -5,6 +5,9 @@
{% block content %}
<h1>Verify Your Email Address</h1>
{{ macros.show_flash_messages() }}
<p>To complete the registration process an email has been sent to you.</p>
<p>Please follow the link in the email to verify your address and complete the registration process</p>

9
ordr2/templates/layout.jinja2

@ -85,15 +85,6 @@ @@ -85,15 +85,6 @@
{% block sidebar %} {% endblock sidebar %}
</div>
<div class="col">
{% for queue in ('ok', 'warning', 'error') %}
{% for message in request.session.pop_flash(queue) %}
{% set css_class = 'danger' if queue == 'error' else queue %}
<div class="alert alert-{{ css_class }} role="alert">
{{message|safe}}
</div>
{% endfor %}
{% endfor %}
{% block content %}
<p>No content</p>
{% endblock content %}

11
ordr2/templates/macros.jinja2

@ -1,3 +1,14 @@ @@ -1,3 +1,14 @@
{% macro show_flash_messages() -%}
{% for queue in ('success', 'warning', 'error') %}
{% for message in request.session.pop_flash(queue) %}
{% set css_class = 'danger' if queue == 'error' else queue %}
<div class="alert alert-{{ css_class }} role="alert">
{{message|safe}}
</div>
{% endfor %}
{% endfor %}
{%- endmacro %}
{% macro white_space_column(size='col-2') -%}
</div><div class="{{ size }}">
{%- endmacro %}