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
 

	
 
from ennstatus.status.functions import mail
 

	
 

	
 
def send_membership_mail(form):
 
    try:
 
        msg = Message('New membership application', sender='ennstatus@enn.lu')
 
        msg.add_recipient(current_app.config['ENNSTATUS_MEMBERSHIP_MAIL'])
 

	
 
        msg.body = render_template('root/membership_mail.txt',
 
                                   username=form.username.data,
 
                                   email=form.email.data,
 
                                   membership=form.membership.data,
 
                                   c3l=form.c3l.data,
 
                                   firstname=form.firstname.data,
 
                                   surname=form.surname.data,
 
                                   street=form.street.data,
 
                                   zip=form.zip.data,
 
                                   city=form.city.data,
 
                                   country=form.country.data,
 
                                   gpg=form.gpg.data
 
                                   )
 
        print(msg.body)
 
        mail.send(msg)
 
        flash('Application successfully sended!', 'success')
 
    except KeyError:
 
        current_app.logger.error('Membership admin not found!')
 
    except AssertionError:
 
        pass
 
    except Exception as e:
 
        current_app.logger.error('Unexpecter error: %s' % e,
 
                                 exc_info=True)
ennstatus/root/views.py
Show inline comments
 
@@ -27,48 +27,49 @@ def services():
 
def partners():
 
    return render_template('root/partners.html')
 

	
 

	
 
@root_page.route('/bridgeprogram')
 
def bridgeprogram():
 
    return render_template('root/bridgeprogram.html')
 

	
 

	
 
@root_page.route('/member')
 
def member():
 
    return render_template('root/member.html')
 

	
 

	
 
@root_page.route('/membership', methods=('GET', 'POST'))
 
def membership():
 

	
 
    current_app.logger.info('Handling membership')
 
    form = MembershipForm()
 

	
 
    if request.method == 'POST':
 
        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)
 

	
 

	
 
@root_page.route('/contact', methods=('GET', 'POST'))
 
def contact():
 

	
 
    current_app.logger.info('Handling contact')
 
    form = BPMForm()
 
    country_choices = [choice[0] for choice in form.country.choices]
 

	
 
    if request.method == 'POST':
 
        current_app.logger.debug('Validating form')
 
        if form.validate_on_submit():
 
            country = form.country.data
 
            return redirect(url_for('root.contact', country=country))
 
    else:
 
        if 'country' in request.args:
 
            country = request.args['country']
 
            if country in country_choices:
 
                current_app.logger.info('Showing country %s' % country)
 
            else:
 
                current_app.logger.warn('Country %s not found' % country)
 
                country = 'luxembourg'
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 %}
 

	
 
{% block metas %}
 
  {{ super() }}
 
  <meta charset="utf-8">
 
  <meta name="application-name" content="Ënnstatus">
 
  <meta name="author" content="Frënn vun der Ënn">
 
{% endblock %}
 

	
 
{% block styles %}
 
  {{ super() }}
 
  <link rel="stylesheet" href="{{ url_for('static', filename='css/ennstatus.css') }}" />
 
  <link rel="shortcut icon" href="{{ url_for('static', filename='images/favicon.png') }}">
 
{% endblock %}
 

	
 
{% block body %}
 
<a href="#content" class="sr-only">Skip to main content</a>
 
<div class="container">
 
  {% block navbar %}
 
  <div class="navbar navbar-default">
 
    <div class="navbar-header">
 
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
 
@@ -95,45 +97,54 @@
 
          </ul>
 
        </li>
 
        <li class="dropdown">
 
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">Statistics <b class="caret"></b></a>
 
          <ul class="dropdown-menu">
 
            <li class="disabled"><a href="#">Statistics</a></li>
 
            <li class="divider"></li>
 
            <li class="dropdown-header">Worldmaps</li>
 
            <li><a href="{{ url_for('stats.worldmap') }}">All nodes</a></li>
 
            <li><a href="{{ url_for('stats.worldmap', server_type='exit') }}">Exit nodes</a></li>
 
            <li><a href="{{ url_for('stats.worldmap', server_type='relay') }}">Relay nodes</a></li>
 
            <li><a href="{{ url_for('stats.worldmap', server_type='bridge') }}">Bridge nodes</a></li>
 
          </ul>
 
        </li>
 
      </ul>
 
      <ul class="nav navbar-nav navbar-right">
 
        <li class="bg-success">
 
          <a href="{{ url_for('root.member') }}">Become a member</a>
 
        </li>
 
      </ul>
 
    </div>
 
  </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>
 
  <footer>
 
    <hr style="margin-bottom: 0.5%;">
 
    <div class="col-md-12 text-center">
 
      <a class="pull-left" href="https://twitter.com/FrennVunDerEnn/" target="_blank"><img src="{{ url_for('static', filename='images/Twitter.png') }}" width="45" height="45"></img></a>
 
      <a href="https://bitbucket.org/fvde/ennstatus-relaunched" target="_blank"><img src="{{ url_for('static', filename='images/BitBucket_Logo.png') }}"></img></a>
 
      <a class="pull-right" rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US"><img alt="Creative Commons License" style="border-width:0" src="https://licensebuttons.net/l/by-nc-sa/3.0/88x31.png" /></a>
 
    </div>
 
    <div class="col-md-12 text-center" style="margin-top: 0.5%; margin-bottom: 0.5%;">
 
      <a href="{{ url_for('root.disclaimer') }}">Disclaimer</a>
 
    </div>
 
  </footer>
 
</div>
 

	
 
{% block scripts %}
 
  {{ super() }}
 
{% endblock %} 
 

	
 
{% endblock %}
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)