# HG changeset patch # User Dennis Fink # Date 2015-10-14 00:52:42 # Node ID 6c4a5b888ec47dd988c29763bc2d5e86e5f9098d # Parent 286ed44ec59c8e234fd2ad679e56cff00f8474c1 Added bridgeprogram application form diff --git a/ennstatus/root/functions.py b/ennstatus/root/functions.py --- a/ennstatus/root/functions.py +++ b/ennstatus/root/functions.py @@ -23,13 +23,21 @@ def send_membership_mail(form): recipients = current_app.config['ENNSTATUS_MEMBERSHIP_MAIL'] with mail.connect() as conn: for recipient in recipients: - msg = Message('New membership application', sender='ennstatus@enn.lu') + msg = Message( + 'New membership application', + sender='ennstatus@enn.lu' + ) msg.add_recipient(recipient) current_app.logger.debug('Before encryption') current_app.logger.debug(body) if current_app.extensions['gnupg']: - encrypted_body = str(current_app.extensions['gnupg'].encrypt(body, recipient, - always_trust=True)) + encrypted_body = str( + current_app.extensions['gnupg'].encrypt( + body, + recipient, + always_trust=True + ) + ) else: encrypted_body = None current_app.logger.debug('After encryption') @@ -38,11 +46,64 @@ def send_membership_mail(form): conn.send(msg) flash('Application successfully sended!', 'success') except KeyError: - flash('Internal server error! Please get in touch with us at info@enn.lu!', 'error') + flash( + 'Internal server error! Please get in touch with us at info@enn.lu!', + 'error' + ) current_app.logger.error('Membership admin not found!') except AssertionError: pass except Exception as e: - flash('Internal server error! Please get in touch with us at info@enn.lu!', 'error') + flash( + 'Internal server error! Please get in touch with us at info@enn.lu!', + 'error' + ) current_app.logger.error('Unexpected error: %s' % e, exc_info=True) + + +def send_bridgeprogram_mail(form): + + try: + body = render_template('root/bridgeprogram_mail.txt', + fullname=form.fullname.data, + email=form.email.data, + bridgename=form.bridgename.data, + duration=form.duration.data, + payment=form.payment.data + ) + + recipients = current_app.config['ENNSTATUS_BRIDGEPROGRAM_MAIL'] + with mail.connect() as conn: + for recipient in recipients: + msg = Message('New bridge program application', + sender='ennstatus@enn.lu') + msg.add_recipient(recipient) + if current_app.extensions['gnupg']: + encrypted_body = str( + current_app.extensions['gnupg'].encrypt( + body, + recipient, + always_trust=True + ) + ) + else: + encrypted_body = None + msg.body = encrypted_body if encrypted_body else body + conn.send(msg) + flash('Application successfully sended!', 'success') + except KeyError: + flash( + 'Internal server error! Please get in touch with us at info@enn.lu', + 'error' + ) + current_app.logger.error('Bridgeprogram admin not found!') + except AssertionError: + pass + except Exception as e: + flash( + 'Internal server error! Please get in touch with us at info@enn.lu!', + 'error' + ) + current_app.logger.error('Unexpected error: %s' % e, + exc_info=True) diff --git a/ennstatus/root/views.py b/ennstatus/root/views.py --- a/ennstatus/root/views.py +++ b/ennstatus/root/views.py @@ -3,7 +3,8 @@ from flask import (Blueprint, render_tem from ennstatus.root.forms import BPMForm, MembershipForm, BridgeprogramForm from ennstatus.root.constants import BPM_ADDRESSES -from ennstatus.root.functions import send_membership_mail +from ennstatus.root.functions import (send_membership_mail, + send_bridgeprogram_mail) root_page = Blueprint('root', __name__) @@ -30,7 +31,16 @@ def partners(): @root_page.route('/bridgeprogram', methods=('GET', 'POST')) def bridgeprogram(): + + current_app.logger.info('Handling bridgeprogram') form = BridgeprogramForm() + + if request.method == 'POST': + current_app.logger.debug('Validation form') + if form.validate_on_submit(): + send_bridgeprogram_mail(form) + return redirect(url_for('root.bridgeprogram')) + return render_template('root/bridgeprogram.html', form=form) diff --git a/ennstatus/templates/root/bridgeprogram_mail.txt b/ennstatus/templates/root/bridgeprogram_mail.txt new file mode 100644 --- /dev/null +++ b/ennstatus/templates/root/bridgeprogram_mail.txt @@ -0,0 +1,12 @@ +Hi, + +We got a new bridge program application! + +Full name: {{ fullname }} +E-Mail: {{ email }} +Bridge Name: {{ bridgename }} +Duration: {{ duration }} +Payment Method: {{ payment }} + +Sincerely, +Ennstatus