lanna_lalala;- commited on
Commit Β·
f92edaa
1
Parent(s): bfa8482
welcome css try
Browse files- phase/Student_view/lesson.py +34 -24
phase/Student_view/lesson.py
CHANGED
|
@@ -4,14 +4,9 @@ import re
|
|
| 4 |
import os
|
| 5 |
from utils import db as dbapi
|
| 6 |
from utils import api as backend_api # unified backend client
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
-
# NEW: import the decoupled mini-quiz module (supports both package and flat runs)
|
| 10 |
-
try:
|
| 11 |
-
from .mini_quiz import ensure_quiz_state, start_quiz, render_quiz, render_results as quiz_results
|
| 12 |
-
except Exception:
|
| 13 |
-
from mini_quiz import ensure_quiz_state, start_quiz, render_quiz, render_results as quiz_results
|
| 14 |
-
|
| 15 |
|
| 16 |
USE_LOCAL_DB = os.getenv("DISABLE_DB", "1") != "1"
|
| 17 |
|
|
@@ -34,7 +29,8 @@ _SS_DEFAULTS = {
|
|
| 34 |
"topic_idx": 0, # 0-based within module
|
| 35 |
"mode": "catalog", # catalog | lesson | quiz | results
|
| 36 |
"topics_cache": {}, # {(level, module_id): [(title, text), ...]}
|
| 37 |
-
|
|
|
|
| 38 |
}
|
| 39 |
|
| 40 |
|
|
@@ -391,7 +387,6 @@ def _get_topics(level: str, module_id: int) -> List[Tuple[str, str]]:
|
|
| 391 |
|
| 392 |
|
| 393 |
def _render_lesson():
|
| 394 |
-
ensure_quiz_state()
|
| 395 |
|
| 396 |
"""Render the lesson interface"""
|
| 397 |
level = st.session_state.get("level", "beginner")
|
|
@@ -550,10 +545,7 @@ def _render_lesson():
|
|
| 550 |
is_last = topic_idx >= len(topics) - 1
|
| 551 |
if is_last:
|
| 552 |
if st.button("Complete Module β", key="complete_btn"):
|
| 553 |
-
st.session_state.
|
| 554 |
-
st.session_state.module_id = None
|
| 555 |
-
st.session_state.topic_idx = 0
|
| 556 |
-
st.success("Module completed! π")
|
| 557 |
st.rerun()
|
| 558 |
else:
|
| 559 |
if st.button("Next Unit β", key="next_btn"):
|
|
@@ -561,6 +553,34 @@ def _render_lesson():
|
|
| 561 |
st.rerun()
|
| 562 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 563 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 564 |
# -----------------------------
|
| 565 |
# Sidebar with Progress & Units
|
| 566 |
# -----------------------------
|
|
@@ -641,10 +661,6 @@ def _render_results():
|
|
| 641 |
module_id = st.session_state.module_id
|
| 642 |
planned = next((m.get("topics", []) for m in MODULES_META[level] if m["id"] == module_id), [])
|
| 643 |
|
| 644 |
-
# Let mini_quiz handle the full results UI (review, feedback, nav)
|
| 645 |
-
quiz_results(planned_topics=planned)
|
| 646 |
-
|
| 647 |
-
|
| 648 |
c1, c2, c3 = st.columns([1, 1, 1])
|
| 649 |
with c1:
|
| 650 |
if st.button("Back to Modules"):
|
|
@@ -735,7 +751,7 @@ def _render_assigned_lesson(lesson_id: int, assignment_id: Optional[int] = None)
|
|
| 735 |
def render():
|
| 736 |
load_css(os.path.join("assets", "styles.css"))
|
| 737 |
_ensure_state()
|
| 738 |
-
|
| 739 |
route = st.session_state.get("lesson_route")
|
| 740 |
if route and route.get("source") == "teacher":
|
| 741 |
_render_assigned_lesson(int(route.get("lesson_id", 0)), route.get("assignment_id"))
|
|
@@ -749,13 +765,7 @@ def render():
|
|
| 749 |
elif mode == "lesson":
|
| 750 |
_render_lesson()
|
| 751 |
elif mode == "quiz":
|
| 752 |
-
|
| 753 |
-
# We can retrieve the module title here for convenience.
|
| 754 |
-
try:
|
| 755 |
-
mod = next(m for m in MODULES_META[st.session_state.level] if m["id"] == st.session_state.module_id)
|
| 756 |
-
render_quiz(lesson_title=mod["title"])
|
| 757 |
-
except Exception:
|
| 758 |
-
render_quiz(lesson_title=None)
|
| 759 |
elif mode == "results":
|
| 760 |
_render_results()
|
| 761 |
else:
|
|
|
|
| 4 |
import os
|
| 5 |
from utils import db as dbapi
|
| 6 |
from utils import api as backend_api # unified backend client
|
| 7 |
+
import quiz as quiz_page
|
| 8 |
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
USE_LOCAL_DB = os.getenv("DISABLE_DB", "1") != "1"
|
| 12 |
|
|
|
|
| 29 |
"topic_idx": 0, # 0-based within module
|
| 30 |
"mode": "catalog", # catalog | lesson | quiz | results
|
| 31 |
"topics_cache": {}, # {(level, module_id): [(title, text), ...]}
|
| 32 |
+
"show_quiz_prompt": False, # <-- controls the post-module popup
|
| 33 |
+
"selected_quiz": None,
|
| 34 |
}
|
| 35 |
|
| 36 |
|
|
|
|
| 387 |
|
| 388 |
|
| 389 |
def _render_lesson():
|
|
|
|
| 390 |
|
| 391 |
"""Render the lesson interface"""
|
| 392 |
level = st.session_state.get("level", "beginner")
|
|
|
|
| 545 |
is_last = topic_idx >= len(topics) - 1
|
| 546 |
if is_last:
|
| 547 |
if st.button("Complete Module β", key="complete_btn"):
|
| 548 |
+
st.session_state.show_quiz_prompt = True
|
|
|
|
|
|
|
|
|
|
| 549 |
st.rerun()
|
| 550 |
else:
|
| 551 |
if st.button("Next Unit β", key="next_btn"):
|
|
|
|
| 553 |
st.rerun()
|
| 554 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 555 |
|
| 556 |
+
# ---- Post-module modal: offer to start Quiz 1 ----
|
| 557 |
+
if st.session_state.get("show_quiz_prompt"):
|
| 558 |
+
# Streamlit 1.25+ has st.modal. If you're on an older version,
|
| 559 |
+
# you can recreate this with a custom overlay.
|
| 560 |
+
with st.modal("Ready for a quick check-in?"):
|
| 561 |
+
st.write("Would you like to do **Quiz 1** to strengthen your knowledge?")
|
| 562 |
+
col_ok, col_skip = st.columns(2)
|
| 563 |
+
|
| 564 |
+
with col_ok:
|
| 565 |
+
if st.button("Yes, start Quiz 1"):
|
| 566 |
+
st.session_state.show_quiz_prompt = False
|
| 567 |
+
st.session_state.mode = "quiz"
|
| 568 |
+
# Assuming your built-in quizzes_data has quiz id 1 for this module
|
| 569 |
+
st.session_state.selected_quiz = 1
|
| 570 |
+
# Optional: make sure quiz starts fresh
|
| 571 |
+
st.session_state.current_q = 0
|
| 572 |
+
st.session_state.answers = {}
|
| 573 |
+
st.rerun()
|
| 574 |
+
|
| 575 |
+
with col_skip:
|
| 576 |
+
if st.button("Maybe later"):
|
| 577 |
+
st.session_state.show_quiz_prompt = False
|
| 578 |
+
# Return to catalog like before
|
| 579 |
+
st.session_state.mode = "catalog"
|
| 580 |
+
st.session_state.module_id = None
|
| 581 |
+
st.session_state.topic_idx = 0
|
| 582 |
+
st.rerun()
|
| 583 |
+
|
| 584 |
# -----------------------------
|
| 585 |
# Sidebar with Progress & Units
|
| 586 |
# -----------------------------
|
|
|
|
| 661 |
module_id = st.session_state.module_id
|
| 662 |
planned = next((m.get("topics", []) for m in MODULES_META[level] if m["id"] == module_id), [])
|
| 663 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 664 |
c1, c2, c3 = st.columns([1, 1, 1])
|
| 665 |
with c1:
|
| 666 |
if st.button("Back to Modules"):
|
|
|
|
| 751 |
def render():
|
| 752 |
load_css(os.path.join("assets", "styles.css"))
|
| 753 |
_ensure_state()
|
| 754 |
+
|
| 755 |
route = st.session_state.get("lesson_route")
|
| 756 |
if route and route.get("source") == "teacher":
|
| 757 |
_render_assigned_lesson(int(route.get("lesson_id", 0)), route.get("assignment_id"))
|
|
|
|
| 765 |
elif mode == "lesson":
|
| 766 |
_render_lesson()
|
| 767 |
elif mode == "quiz":
|
| 768 |
+
quiz_page.show_page()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 769 |
elif mode == "results":
|
| 770 |
_render_results()
|
| 771 |
else:
|