Fausto Busuito
commited on
Commit
·
d77ef80
1
Parent(s):
8d9d8e8
Application changes
Browse files- app.py +18 -9
- templates/quiz.html +4 -2
app.py
CHANGED
@@ -27,6 +27,7 @@ def start():
|
|
27 |
session['current_question'] = 0
|
28 |
|
29 |
selected_file = request.form['file']
|
|
|
30 |
file_path = os.path.join(QUESTIONS_FOLDER, selected_file)
|
31 |
with open(file_path, 'r') as file:
|
32 |
questions = json.load(file)
|
@@ -40,19 +41,27 @@ def quiz():
|
|
40 |
return redirect(url_for('index'))
|
41 |
|
42 |
if request.method == 'POST':
|
43 |
-
|
44 |
-
if
|
45 |
-
|
46 |
-
if answer
|
47 |
-
session['
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
return redirect(url_for('results'))
|
52 |
|
53 |
return render_template('quiz.html', question=session['questions'][session['current_question']],
|
54 |
question_number=session['current_question'] + 1,
|
55 |
-
total_questions=len(session['questions'])
|
|
|
56 |
|
57 |
@app.route('/results')
|
58 |
def results():
|
|
|
27 |
session['current_question'] = 0
|
28 |
|
29 |
selected_file = request.form['file']
|
30 |
+
session['selected_file'] = selected_file
|
31 |
file_path = os.path.join(QUESTIONS_FOLDER, selected_file)
|
32 |
with open(file_path, 'r') as file:
|
33 |
questions = json.load(file)
|
|
|
41 |
return redirect(url_for('index'))
|
42 |
|
43 |
if request.method == 'POST':
|
44 |
+
action = request.form.get('action')
|
45 |
+
if action == 'next':
|
46 |
+
answer = request.form.get('answer')
|
47 |
+
if answer:
|
48 |
+
session['answers'].append(answer)
|
49 |
+
if answer in session['questions'][session['current_question']]['correct']:
|
50 |
+
session['score'] += 1
|
51 |
+
session['current_question'] += 1
|
52 |
+
if session['current_question'] >= len(session['questions']):
|
53 |
+
return redirect(url_for('results'))
|
54 |
+
elif action == 'previous':
|
55 |
+
session['current_question'] -= 1
|
56 |
+
if session['current_question'] < 0:
|
57 |
+
session['current_question'] = 0
|
58 |
+
elif action == 'end':
|
59 |
return redirect(url_for('results'))
|
60 |
|
61 |
return render_template('quiz.html', question=session['questions'][session['current_question']],
|
62 |
question_number=session['current_question'] + 1,
|
63 |
+
total_questions=len(session['questions']),
|
64 |
+
selected_file=session['selected_file'])
|
65 |
|
66 |
@app.route('/results')
|
67 |
def results():
|
templates/quiz.html
CHANGED
@@ -7,7 +7,7 @@
|
|
7 |
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
|
8 |
</head>
|
9 |
<body>
|
10 |
-
<h1>Question {{ question_number }} of {{ total_questions }}</h1>
|
11 |
<p>{{ question.question }}</p>
|
12 |
<form action="{{ url_for('quiz') }}" method="post">
|
13 |
{% for option in question.options %}
|
@@ -15,7 +15,9 @@
|
|
15 |
<label for="{{ loop.index }}">{{ option }}</label><br>
|
16 |
{% endfor %}
|
17 |
<br>
|
18 |
-
<button type="submit">
|
|
|
|
|
19 |
</form>
|
20 |
</body>
|
21 |
</html>
|
|
|
7 |
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
|
8 |
</head>
|
9 |
<body>
|
10 |
+
<h1>Question {{ question_number }} of {{ total_questions }} - {{ selected_file }}</h1>
|
11 |
<p>{{ question.question }}</p>
|
12 |
<form action="{{ url_for('quiz') }}" method="post">
|
13 |
{% for option in question.options %}
|
|
|
15 |
<label for="{{ loop.index }}">{{ option }}</label><br>
|
16 |
{% endfor %}
|
17 |
<br>
|
18 |
+
<button type="submit" name="action" value="previous">Previous</button>
|
19 |
+
<button type="submit" name="action" value="next">Next</button>
|
20 |
+
<button type="submit" name="action" value="end">End Session</button>
|
21 |
</form>
|
22 |
</body>
|
23 |
</html>
|