# HG changeset patch # User Dennis Fink # Date 2015-02-15 23:29:34 # Node ID 43d78381c78ae1217a3ceb78487f72f37be810a7 # Parent 2a46bac0cfc2faa7cac7694c66ed1e05961a7c3e Added flash message for membership application form diff --git a/ennstatus/root/functions.py b/ennstatus/root/functions.py --- a/ennstatus/root/functions.py +++ b/ennstatus/root/functions.py @@ -1,4 +1,4 @@ -from flask import render_template, current_app +from flask import render_template, current_app, flash from flask_mail import Mail, Message @@ -25,6 +25,7 @@ def send_membership_mail(form): ) print(msg.body) mail.send(msg) + flash('Application successfully sended!', 'success') except KeyError: current_app.logger.error('Membership admin not found!') except AssertionError: diff --git a/ennstatus/root/views.py b/ennstatus/root/views.py --- a/ennstatus/root/views.py +++ b/ennstatus/root/views.py @@ -48,6 +48,7 @@ def membership(): current_app.logger.debug('Validating form') if form.validate_on_submit(): send_membership_mail(form) + return redirect(url_for('root.member')) return render_template('root/membership.html', form=form) diff --git a/ennstatus/templates/base.html b/ennstatus/templates/base.html --- a/ennstatus/templates/base.html +++ b/ennstatus/templates/base.html @@ -1,5 +1,7 @@ {% extends "bootstrap/base.html" %} +{% import 'macros.html' as base_macros with context %} + {% block title %} Frënn vun der Ënn - {{ title }} {% endblock %} @@ -116,6 +118,15 @@ {% endblock %}
+ {% with messages = get_flashed_messages(with_categories=True) %} + {% if messages %} +
+ {% for category, message in messages %} + {{ base_macros.display_error(category, message) }} + {% endfor %} +
+ {% endif %} + {% endwith %} {% block content %} {% endblock %}
diff --git a/ennstatus/templates/macros.html b/ennstatus/templates/macros.html new file mode 100644 --- /dev/null +++ b/ennstatus/templates/macros.html @@ -0,0 +1,18 @@ +{% set category_colors = {'error': 'alert-danger', 'success': 'alert-success'} %} + +{% macro get_category_color(category) %} + {% if category in category_colors %} + {{ category_colors[category] }} + {% else %} + "alert-info" + {% endif %} +{% endmacro %} + + +{% macro display_error(category, message) %} + {% set color = get_category_color(category) %} +
+ + {{ message }} +
+{% endmacro %}