-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
executable file
·68 lines (42 loc) · 1.4 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
65
66
67
68
#!/usr/bin/env python3
from flask import Flask, render_template, request, jsonify
from flask_bootstrap import Bootstrap
import inquiry
def create_app():
app = Flask(__name__)
Bootstrap(app)
return app
app = create_app()
@app.route('/')
def index():
return render_template('start.html')
@app.route('/<iid>/start', methods=['POST'])
def start(iid):
data = request.form
if 'student_id' not in data or 'test_code' not in data:
return jsonify({'status': 'error', 'message': 'missing fields'}), 400
student_id = data['student_id']
test_code = data['test_code']
i = inquiry.load(iid)
poll = i.first_poll() # logic
subject = i.next_subject() # data
return render_template('inquiry.html', student_id=student_id,
test_code=test_code, poll=poll,
subject=subject)
@app.route('/<iid>/next')
def next_inquiry():
# save answers
data = request.form
if 'registro' not in data or 'test_code' not in data
or 'answers' not in data or 'poll_id' not in data:
return jsonify({'status': 'error', 'message': 'missing fields'}), 400
answers =
student_id = data['registro']
test_code = data['test_code']
i = inquiry.load(iid)
i.save_answers(poll_id, answers)
s = inquiry.next_subject() # data
return render_template('inquiry.html', student_id=student_id,
test_code=test_code, inquiry=i, subject=s)
if __name__ == '__main__':
app.run(debug=True)