This repository has been archived on 2023-02-07. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-bfct/blender-bfct/application/controllers/main.py
Francesco Siddi 76ece294db Email framework
Notifications will be sent when someone submits an application.
2014-07-16 14:38:26 +02:00

87 lines
3.4 KiB
Python

from application import app, db
from application.emails import send_email_notification_new_submission
from application.models.users import *
from application.models.applications import Application, Skill
from flask import render_template, redirect, url_for, request, flash
from flask.ext.security import login_required
from flask.ext.security.core import current_user
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
from flask_wtf import Form
from wtforms import TextField, TextAreaField, BooleanField, SelectMultipleField
from wtforms.validators import DataRequired
from wtforms.fields.html5 import URLField
from wtforms.validators import url
class ApplicationForm(Form):
network_profile = TextField('Blender Network Profile')
website = URLField(validators=[url(), DataRequired()])
city_country = TextField('City and Country', validators=[DataRequired()])
teaching = BooleanField('Teaching')
institution_name = TextField('School or institution name')
skills = SelectMultipleField('Areas of expertise', coerce=int)
video_example = URLField(validators=[url(), DataRequired()])
written_example = URLField(validators=[url(), DataRequired()])
portfolio_cv = URLField(validators=[url(), DataRequired()])
bio_message = TextAreaField('Your message for the board', validators=[DataRequired()])
# Views
@app.route('/')
def homepage():
return render_template('index.html', title='home')
@app.route('/become-a-trainer/')
def become_a_trainer():
return render_template('become_a_trainer.html', title='become_a_trainer')
@app.route('/apply', methods=['GET', 'POST'])
@login_required
def apply():
application = Application.query.filter_by(blender_id=current_user.id).first()
if application:
return redirect(url_for('my_application'))
else:
form = ApplicationForm()
form.skills.choices = [(s.id, s.name) for s in Skill.query.all()]
if form.validate_on_submit():
application = Application(
blender_id=current_user.id,
network_profile=form.website.data,
website=form.website.data,
city_country=form.city_country.data,
institution_name=form.institution_name.data,
video_example=form.video_example.data,
written_example=form.written_example.data,
portfolio_cv=form.portfolio_cv.data,
bio_message=form.bio_message.data,
status='submitted')
for skill in form.skills.data:
s = Skill.query.get(skill)
application.skills.append(s)
db.session.add(application)
db.session.commit()
send_email_notification_new_submission(application)
return redirect(url_for('my_application'))
# print form.errors
return render_template('apply.html',
title='apply',
form=form)
@app.route('/my-application')
@login_required
def my_application():
try:
application = Application.query.filter_by(blender_id=current_user.id).one()
except MultipleResultsFound:
flash('You have submitted more than one application. Get in touch with support@blendernetwork.org.')
return render_template('index.html')
except NoResultFound:
return redirect(url_for('apply'))
return render_template('my_application.html',
application=application)