Files @ c371e8f90946
Branch filter:

Location: FVDE/ennstatus/ennstatus/root/views.py

Dennis Fink
Initalize csrf
from flask import (Blueprint, render_template, current_app,
                   request, redirect, url_for, flash)

from ennstatus.root.forms import BPMForm, MembershipForm
from ennstatus.root.constants import BPM_ADDRESSES
from ennstatus.root.functions import send_membership_mail

root_page = Blueprint('root', __name__)


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


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


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


@root_page.route('/partners')
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')
        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'
        else:
            current_app.logger.info('Using default country')
            country = 'luxembourg'

    form.country.data = country

    address = BPM_ADDRESSES[country]

    return render_template('root/contact.html', form=form, address=address)


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


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