diff --git a/ennstatus/donate/constants.py b/ennstatus/donate/constants.py new file mode 100644 --- /dev/null +++ b/ennstatus/donate/constants.py @@ -0,0 +1,39 @@ + +BPM_ADDRESSES = { + 'united_kingdom': { + 'address': '372 Old Street', + 'postal_code': 'EC1V 9AU', + 'city': 'London', + 'country': 'United Kingdom', + }, + 'united_states': { + 'address': '8345 NW 66 Street 2000', + 'postal_code': '33166-2626', + 'city': 'Miami', + 'country': 'United States of America', + }, + 'germany': { + 'address': 'Zum Bürgerwehr 28', + 'postal_code': 'D-5416', + 'city': 'Wittlich', + 'country': 'Germany', + }, + 'belgium': { + 'address': '3, Rue des Deux Luxembourg', + 'postal_code': 'B-6791', + 'city': 'Athus', + 'country': 'Belgium', + }, + 'france': { + 'address': 'RN 18 Les Maragolles', + 'postal_code': 'F-54720', + 'city': 'Lexy', + 'country': 'France', + }, + 'luxembourg': { + 'address': '34, Rue Gabriel Lippmann', + 'postal_code': 'L-5362', + 'city': 'Munsbach', + 'country': 'Luxembourg', + }, +} diff --git a/ennstatus/donate/forms.py b/ennstatus/donate/forms.py --- a/ennstatus/donate/forms.py +++ b/ennstatus/donate/forms.py @@ -3,5 +3,21 @@ from wtforms import SelectField from wtforms.validators import DataRequired +COUNTRIES = [ + ('luxembourg', 'Luxembourg'), + ('united_kingdom', 'United Kingdom'), + ('united_states', 'United States of America'), + ('belgium', 'Belgium'), + ('france', 'France'), + ('germany', 'Germany'), +] + + class DateForm(Form): date = SelectField('date', validators=[DataRequired()]) + + +class BPMForm(Form): + country = SelectField('Country', + validators=[DataRequired()], + choices=COUNTRIES) diff --git a/ennstatus/donate/views.py b/ennstatus/donate/views.py --- a/ennstatus/donate/views.py +++ b/ennstatus/donate/views.py @@ -1,8 +1,9 @@ from flask import (Blueprint, render_template, request, redirect, url_for, current_app) -from ennstatus.donate.forms import DateForm +from ennstatus.donate.forms import DateForm, BPMForm from ennstatus.donate.functions import load_csv, get_choices +from ennstatus.donate.constants import BPM_ADDRESSES donate_page = Blueprint('donate', __name__) @@ -37,9 +38,36 @@ def flattr(): return render_template('donate/flattr.html') -@donate_page.route('/bpm') +@donate_page.route('/bpm', methods=('GET', 'POST')) def bpm(): - return render_template('donate/bpm.html') + + current_app.logger.info('Handling BPM') + 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('donate.bpm', 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('donate/bpm.html', form=form, + address=address) @donate_page.route('/received', diff --git a/ennstatus/templates/donate/bpm.html b/ennstatus/templates/donate/bpm.html --- a/ennstatus/templates/donate/bpm.html +++ b/ennstatus/templates/donate/bpm.html @@ -13,9 +13,29 @@ Marlon Brandobrainyquote +
We accept BPM points as they will be used for our BPM Parcel Station. The parcel station is used for receiving and sending mails and packages around the world!
+ {% endblock %}