-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
47 lines (41 loc) · 1.4 KB
/
run.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
from flask import Flask, render_template, request
import json
import os
import unirest
HEADERS = {'Accept':'application/json', 'Content-Type':'application-json'}
app = Flask(__name__)
app.debug = True
def get(famID):
response = unirest.get(os.environ['CLERK_URL'] + 'tour/' + famID)
return response.body
@app.route('/')
def index():
#they are submitting the form, so post and redirect
if request.args.get('q1') is not None:
#post the data
#TODO: validate that this is an actual family
data = {}
data['family'] = request.args.get('family')
data['guide_review'] = request.args.get('q1')
data['wanting'] = request.args.get('q2')
data['extraneous'] = request.args.get('q3')
response = unirest.post(os.environ['CLERK_URL'] + 'followup/', headers=HEADERS,
params = json.dumps(data))
print response.body
#redirect
return render_template('submitted.html')
#they are asking for a new form
famID = request.args.get('id')
if famID is None:
return render_template('index.html')
else:
fam = get(famID)
try:
name = fam['name']
except TypeError:
return "invalid ID in URL"
else:
data = {'name': name, 'id':famID}
return render_template('followup.html', data=data)
if __name__ == '__main__':
app.run()