Changeset - 6c4a5b888ec4
[Not reviewed]
version_5
0 2 1
Dennis Fink - 9 years ago 2015-10-14 00:52:42
dennis.fink@c3l.lu
Added bridgeprogram application form
3 files changed with 89 insertions and 6 deletions:
0 comments (0 inline, 0 general)
ennstatus/root/functions.py
Show inline comments
 
@@ -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)
ennstatus/root/views.py
Show inline comments
 
@@ -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)
 

	
 

	
ennstatus/templates/root/bridgeprogram_mail.txt
Show inline comments
 
new file 100644
 
Hi,
 

	
 
We got a new bridge program application!
 

	
 
Full name: {{ fullname }}
 
E-Mail: {{ email }}
 
Bridge Name: {{ bridgename }}
 
Duration: {{ duration }}
 
Payment Method: {{ payment }}
 

	
 
Sincerely,
 
Ennstatus
0 comments (0 inline, 0 general)