Fausto Busuito commited on
Commit
e0c2fd7
·
1 Parent(s): 5775f49

Application changes

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -25,6 +25,7 @@ def start():
25
  session['answers'] = []
26
  session['current_question'] = 0
27
  session['start_time'] = time.time()
 
28
 
29
  selected_file = request.form['file']
30
  session['selected_file'] = os.path.splitext(selected_file)[0] # Remove file extension
@@ -41,6 +42,9 @@ def quiz():
41
  if 'questions' not in session or 'current_question' not in session:
42
  return redirect(url_for('index'))
43
 
 
 
 
44
  if request.method == 'POST':
45
  action = request.form.get('action')
46
  if action == 'next':
@@ -50,10 +54,10 @@ def quiz():
50
  if multiple_selection:
51
  required_answers = 2
52
  if len(answers) == required_answers:
53
- session['answers'][session['current_question']] = answers
54
  else:
55
  if answers:
56
- session['answers'][session['current_question']] = answers
57
  session['current_question'] += 1
58
  if session['current_question'] >= len(session['questions']):
59
  return redirect(url_for('results'))
@@ -69,12 +73,17 @@ def quiz():
69
  elapsed_time = time.time() - session['start_time']
70
  elapsed_time_str = time.strftime('%H:%M:%S', time.gmtime(elapsed_time))
71
 
72
- previous_answers = session['answers'][session['current_question']] if session['current_question'] < len(session['answers']) else []
 
 
 
 
 
73
 
74
  # Debugging statements
75
  print(f"Current question index: {session['current_question']}")
76
  print(f"Previous answers: {previous_answers}")
77
- print(f"Session answers: {session['answers']}")
78
 
79
  return render_template('quiz.html', question=question,
80
  question_number=session['current_question'] + 1,
 
25
  session['answers'] = []
26
  session['current_question'] = 0
27
  session['start_time'] = time.time()
28
+ session['user_answers'] = []
29
 
30
  selected_file = request.form['file']
31
  session['selected_file'] = os.path.splitext(selected_file)[0] # Remove file extension
 
42
  if 'questions' not in session or 'current_question' not in session:
43
  return redirect(url_for('index'))
44
 
45
+ if 'user_answers' not in session:
46
+ session['user_answers'] = []
47
+
48
  if request.method == 'POST':
49
  action = request.form.get('action')
50
  if action == 'next':
 
54
  if multiple_selection:
55
  required_answers = 2
56
  if len(answers) == required_answers:
57
+ session['user_answers'].append((session['current_question'], answers))
58
  else:
59
  if answers:
60
+ session['user_answers'].append((session['current_question'], answers))
61
  session['current_question'] += 1
62
  if session['current_question'] >= len(session['questions']):
63
  return redirect(url_for('results'))
 
73
  elapsed_time = time.time() - session['start_time']
74
  elapsed_time_str = time.strftime('%H:%M:%S', time.gmtime(elapsed_time))
75
 
76
+ # Find the previous answers for the current question
77
+ previous_answers = []
78
+ for q_index, answers in session['user_answers']:
79
+ if q_index == session['current_question']:
80
+ previous_answers = answers
81
+ break
82
 
83
  # Debugging statements
84
  print(f"Current question index: {session['current_question']}")
85
  print(f"Previous answers: {previous_answers}")
86
+ print(f"Session user answers: {session['user_answers']}")
87
 
88
  return render_template('quiz.html', question=question,
89
  question_number=session['current_question'] + 1,