This repository has been archived by the owner on Mar 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
64 lines (46 loc) · 1.91 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from flask import Flask, jsonify, redirect, render_template, request, url_for
import db
app = Flask(__name__)
@app.before_first_request
def initialize():
db.setup()
@app.route('/')
def home():
return render_template("home.html")
@app.route('/survey')
def survey():
return render_template("survey.html")
@app.route('/decline')
def decline():
return render_template("decline.html")
@app.route('/thanks', methods=['GET', 'POST'])
def thanks():
if request.method == 'POST':
name = request.form['name']
participation = request.form['participation'] if 'participation' in request.form else None
last_participated, participation_info = None, None
if participation == 'yes':
last_participated = request.form['last-participated'] if 'last-participated' in request.form else None
participation_info = request.form['participation-info'] if 'participation-info' in request.form else None
learn_more = 'learn-more' in request.form and request.form['learn-more'] == 'on'
with db.get_db_cursor(commit=True) as cur:
cur.execute("insert into results (name, participation, last_participated, participation_info, learn_more) values (%s, %s, %s, %s, %s)",
(name, participation, last_participated, participation_info, learn_more,))
return render_template("thanks.html")
@app.route('/admin/summary')
def summary():
data = api_results(False)
return render_template("summary.html", data=data)
@app.route('/api/results')
def api_results(json=True):
with db.get_db_cursor() as cur:
cur.execute("select * from results")
rows = cur.fetchall()
if 'reverse' in request.args and request.args['reverse'] == 'true':
rows = list(reversed(rows))
results = []
for item in rows:
results.append(dict(item))
return jsonify(results) if json else results
if __name__ == '__main__':
pass