From 511e5d0c252ae3ed96b00cf0419993d32da47d3e Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Tue, 24 Oct 2017 17:42:25 +0200 Subject: [PATCH] moved display of flash messages to template macros --- ordr2/events.py | 31 ++++++++++++------- .../account/forgot_password_email.jinja2 | 3 ++ .../account/forgot_password_form.jinja2 | 3 ++ ordr2/templates/account/login.jinja2 | 5 +-- .../account/registration_completed.jinja2 | 3 ++ .../account/registration_confirmation.jinja2 | 3 ++ ordr2/templates/layout.jinja2 | 9 ------ ordr2/templates/macros.jinja2 | 11 +++++++ 8 files changed, 45 insertions(+), 23 deletions(-) diff --git a/ordr2/events.py b/ordr2/events.py index df0a97b..a331d28 100644 --- a/ordr2/events.py +++ b/ordr2/events.py @@ -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): 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): 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): 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) diff --git a/ordr2/templates/account/forgot_password_email.jinja2 b/ordr2/templates/account/forgot_password_email.jinja2 index 1b43ee5..fc44c23 100644 --- a/ordr2/templates/account/forgot_password_email.jinja2 +++ b/ordr2/templates/account/forgot_password_email.jinja2 @@ -4,6 +4,9 @@ {% block content %}

Password Reset Link

+ + {{ macros.show_flash_messages() }} +

To reset your password, an email has been sent to you.

Please follow the link in the email to set a new password.

diff --git a/ordr2/templates/account/forgot_password_form.jinja2 b/ordr2/templates/account/forgot_password_form.jinja2 index 5ec26b9..d678972 100644 --- a/ordr2/templates/account/forgot_password_form.jinja2 +++ b/ordr2/templates/account/forgot_password_form.jinja2 @@ -4,6 +4,9 @@ {% block content %}

Forgotten password?

+ + {{ macros.show_flash_messages() }} +
diff --git a/ordr2/templates/account/login.jinja2 b/ordr2/templates/account/login.jinja2 index 018d7fb..7f3273d 100644 --- a/ordr2/templates/account/login.jinja2 +++ b/ordr2/templates/account/login.jinja2 @@ -3,8 +3,9 @@ {% block title %} Ordr | Login Failed {% endblock title %} {% block content %} -

Try again…

-

You entered the wrong username or password.

+

Log In

+ + {{ macros.show_flash_messages() }} diff --git a/ordr2/templates/account/registration_completed.jinja2 b/ordr2/templates/account/registration_completed.jinja2 index 28bbe28..c7e17d6 100644 --- a/ordr2/templates/account/registration_completed.jinja2 +++ b/ordr2/templates/account/registration_completed.jinja2 @@ -4,6 +4,9 @@ {% block content %}

Account Registration Completed

+ + {{ macros.show_flash_messages() }} +

Thank you for verifying your email address.

Before you can start ordering, an administrator must activate your account

You'll receive an email when your account is activated

diff --git a/ordr2/templates/account/registration_confirmation.jinja2 b/ordr2/templates/account/registration_confirmation.jinja2 index b0fe485..40d8490 100644 --- a/ordr2/templates/account/registration_confirmation.jinja2 +++ b/ordr2/templates/account/registration_confirmation.jinja2 @@ -5,6 +5,9 @@ {% block content %}

Verify Your Email Address

+ + {{ macros.show_flash_messages() }} +

To complete the registration process an email has been sent to you.

Please follow the link in the email to verify your address and complete the registration process

diff --git a/ordr2/templates/layout.jinja2 b/ordr2/templates/layout.jinja2 index 94feda7..b84cdf1 100644 --- a/ordr2/templates/layout.jinja2 +++ b/ordr2/templates/layout.jinja2 @@ -85,15 +85,6 @@ {% block sidebar %} {% endblock sidebar %}
- {% for queue in ('ok', 'warning', 'error') %} - {% for message in request.session.pop_flash(queue) %} - {% set css_class = 'danger' if queue == 'error' else queue %} -
- {{message|safe}} -
- {% endfor %} - {% endfor %} - {% block content %}

No content

{% endblock content %} diff --git a/ordr2/templates/macros.jinja2 b/ordr2/templates/macros.jinja2 index 5d595cb..4e77a0c 100644 --- a/ordr2/templates/macros.jinja2 +++ b/ordr2/templates/macros.jinja2 @@ -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 %} +
+ {{message|safe}} +
+ {% endfor %} + {% endfor %} +{%- endmacro %} + {% macro white_space_column(size='col-2') -%}
{%- endmacro %}