forked from lilili77/UI-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.py
74 lines (59 loc) · 1.84 KB
/
application.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
69
70
71
72
73
74
from flask import Flask
from flask import render_template
from flask import Response, request, jsonify
import pandas as pd
import numpy as np
application = Flask(__name__)
# === Data =============================================================================================================
# Quiz data
num_of_quiz = 6
usr_choice = []
quiz_data = []
# init usr_choice
for i in range(num_of_quiz):
usr_choice.append({'choice':None,'correct':False})
# === ROUTES ===========================================================================================================
@application.route('/')
def homepage():
return render_template('homepage.html')
# Quiz Routes
@application.route('/quiz/')
def quiz_start():
'''
Initial page to Start quiz
'''
return render_template('quiz_start.html')
@application.route('/quiz/<qid>')
def quiz(qid):
'''
Render quiz/<qid>
qid: quiz id start from 0
usr_choice: global var; usr_choice[qid] get user's choice for the qid
quiz_data:
'''
global usr_choice
global quiz_data
if qid != len(usr_choice)-1:
return render_template('quiz.html',qid=qid, usr_choice=usr_choice)
else:
# drag and drop quiz
return render_template('quiz.html',qid=qid, usr_choice=usr_choice)
@application.route('/update_usr_choice/<qid>', methods=['POST'])
def update_usr_choice(qid):
'''
Ajax call to update global var usr_choice
'''
pass
# json_data = request.get_json()
#
# return jsonify(data = data)
@application.route('/quiz/score')
def quiz_score():
'''
Quiz score page
Calculate score from usr_choice
'''
return render_template('quiz_score.html')
# === Main ===========================================================================================================
if __name__ == '__main__':
application.run(debug = True)