exam_kiosk_v1 / pages /3_Take_Exam.py
louiecerv's picture
fixed issues in the Take Quiz form
67386c7
import streamlit as st
import json
from quiz_gui_helper import _QuizGUI
if "current_question" not in st.session_state:
st.session_state.current_question = 0
if "quiz_started" not in st.session_state:
st.session_state.quiz_started = False
if "quiz_loaded" not in st.session_state:
st.session_state.quiz_loaded = False
def main():
if not st.session_state.quiz_loaded:
st.error("Please load an exam first!")
else:
if st.session_state.quiz_started:
# start_quiz will handle if the quiz is completed
quiz_data = st.session_state.quiz_data
_QuizGUI(quiz_data).start_quiz()
if not st.session_state.quiz_completed:
st.write("You are currently taking the active exam.")
_QuizGUI(quiz_data).confirm_end_quiz()
else:
#read the metadata and quiz_data from the session state
metadata = st.session_state.metadata
quiz_data = st.session_state.quiz_data
quiz_app = _QuizGUI(quiz_data)
quiz_app.load_quiz(metadata)
st.write("Click Start Exam to taking the exam.")
if st.button("Start Exam"):
st.session_state.page_access["Take Exam"] = True
st.session_state.page_access["View Results"] = False
st.session_state.current_question = 0
st.session_state.user_answers = []
st.session_state.completed = False
st.session_state.score = 0
_QuizGUI(quiz_data).start_quiz()
st.session_state.quiz_started = True
st.rerun()
if __name__ == "__main__":
main()