import streamlit as st
from settings import TECHNOLOGIES_LIST
class Layout:
@staticmethod
def render_header():
"""
Renders the header of the application with a logo and title.
"""
st.markdown(
"""
""",
unsafe_allow_html=True
)
@staticmethod
def render_signup_form():
"""
Renders the signup form for candidate details.
:return: Tuple containing name, email, experience, and selected technology.
"""
with st.form("signup_form"):
st.header("Sign Up")
name = st.text_input("Full Name", help="Please enter your full name")
email = st.text_input("Email", help="Please enter your email")
experience = st.slider("Total Years of Experience", 0, 20, 0, help="Select your years of experience")
technology = st.selectbox("Technology", TECHNOLOGIES_LIST, help="Select your primary technology")
submit = st.form_submit_button("Start Test")
if submit:
if not name or not email:
st.error("Name and Email are required! Please fill both fields.")
return None, None, None, None, None
return name, email, experience, technology, submit
return None, None, None, None, None
@staticmethod
def render_instructions():
"""
Renders test instructions for the candidates.
"""
st.header("Instructions")
st.info(
"""
1. Each question is multiple-choice.
"""
)
@staticmethod
def render_progress_bar(current, total):
"""
Renders a progress bar for the test.
:param current: Current progress (integer).
:param total: Total progress (integer).
"""
st.progress(current / total)
@staticmethod
def render_test_question(question, idx):
"""
Renders a single test question with multiple-choice options.
:param question: Dictionary containing question details.
:param idx: Index of the question for unique Streamlit keys.
:return: Selected option from the user.
"""
st.markdown(f"""
Question {idx + 1}: {question['question']}
""",
unsafe_allow_html=True,
)
selected_option = st.radio(
"",
[question['option1'], question['option2'], question['option3'], question['option4']],
key=f"q{idx}",
label_visibility="collapsed",
help="Choose the correct answer",
index=None
)
st.markdown("---")
return selected_option
@staticmethod
def render_completion_message(score, total):
"""
Displays a completion message after the test is submitted.
:param score: Total score obtained by the candidate.
:param total: Total questions in the test.
"""
st.success("Test completed successfully! Great job on completing it. Thank you for your effort and dedication.")