From 5803efd4bb3b9dfd538153767496c7281cf9ccf6 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sat, 10 Oct 2015 14:26:52 -0700 Subject: [PATCH] Re-combine index handlers --- app/main/views.py | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/app/main/views.py b/app/main/views.py index f3d8276..7903932 100644 --- a/app/main/views.py +++ b/app/main/views.py @@ -7,9 +7,22 @@ from .utils import getTemps, avg_air_temp, ann_air_indices, \ from .models import DB -@main.route('/', methods=['GET']) +@main.route('/', methods=['GET', 'POST']) def index(): - form = generateForm() + form = AKIForm() + form.community.choices = communitiesSelect() + form.dataset.choices = datasetsSelect() + + if form.validate_on_submit(): + session['community'] = request.form['community'] + session['minyear'] = request.form['minyear'] + session['maxyear'] = request.form['maxyear'] + if session['minyear'] > session['maxyear']: + session['maxyear'] = session['minyear'] + + session['datasets'] = request.form['dataset'] + return redirect(url_for('main.index')) + session['community_data'] = None session['avg_temp'] = None session['avg_indices'] = None @@ -39,23 +52,6 @@ def index(): return render_template('main/index.html', form=form) -@main.route('/', methods=['POST']) -def index_submit(): - form = generateForm() - if form.validate(): - session['community'] = request.form['community'] - session['minyear'] = request.form['minyear'] - session['maxyear'] = request.form['maxyear'] - if session['minyear'] > session['maxyear']: - session['maxyear'] = session['minyear'] - - session['datasets'] = request.form['dataset'] - return redirect(url_for('main.index')) - else: - # TODO: Fix post-POST handling - return render_template('main/index.html', form=form) - - @main.route('/datatypes') def datatypes(): return render_template('main/datatypes.html') @@ -111,10 +107,3 @@ def delete(): record = request.args.get('record', '') session['save'].pop(record) return redirect(url_for('main.index')) - - -def generateForm(): - form = AKIForm() - form.community.choices = communitiesSelect() - form.dataset.choices = datasetsSelect() - return form