Changeset - 43d78381c78a
[Not reviewed]
default
0 3 1
Dennis Fink - 10 years ago 2015-02-15 23:29:34
dennis.fink@c3l.lu
Added flash message for membership application form
4 files changed with 32 insertions and 1 deletions:
0 comments (0 inline, 0 general)
ennstatus/root/functions.py
Show inline comments
 
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:
ennstatus/root/views.py
Show inline comments
 
@@ -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)
 

	
ennstatus/templates/base.html
Show inline comments
 
{% 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 @@
 
  </div>
 
  {% endblock %}
 
  <div class="row" id="content">
 
  {% with messages = get_flashed_messages(with_categories=True) %}
 
    {% if messages %}
 
      <div class="col-md-12">
 
        {% for category, message in messages %}
 
          {{ base_macros.display_error(category, message) }}
 
        {% endfor %}
 
      </div>
 
    {% endif %}
 
  {% endwith %} 
 
  {% block content %}
 
  {% endblock %}
 
  </div>
ennstatus/templates/macros.html
Show inline comments
 
new file 100644
 
{% 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) %}
 
  <div class="{{ ' '.join(('alert', color)) }}">
 
    <button type="button" class="close" data-dismiss="alert">&times;</button>
 
    {{ message }}
 
  </div>
 
{% endmacro %}
0 comments (0 inline, 0 general)