lanna_lalala;- commited on
Commit ·
4b8f2ac
1
Parent(s): ea75112
updating
Browse files- phase/Student_view/lesson.py +10 -5
phase/Student_view/lesson.py
CHANGED
|
@@ -52,20 +52,25 @@ def _resolve_lesson_title_by_id(lesson_id: int) -> str:
|
|
| 52 |
def _fetch_lesson_content_via_backend(lesson_id: int, topic_index: int, *,
|
| 53 |
title: Optional[str] = None,
|
| 54 |
topic_name: Optional[str] = None) -> Optional[str]:
|
| 55 |
-
"""
|
| 56 |
-
Ask the backend lesson agent for the content of a topic.
|
| 57 |
-
Expected shape: { lesson_content | content }
|
| 58 |
-
"""
|
| 59 |
title = title or _resolve_lesson_title_by_id(lesson_id)
|
| 60 |
module_id = str(lesson_id)
|
| 61 |
topic = topic_name or f"Topic {int(topic_index)}"
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
if isinstance(resp, dict):
|
| 65 |
return resp.get("lesson_content") or resp.get("content")
|
| 66 |
return None
|
| 67 |
|
| 68 |
|
|
|
|
| 69 |
# --- Load external CSS ---
|
| 70 |
def load_css(file_name):
|
| 71 |
try:
|
|
|
|
| 52 |
def _fetch_lesson_content_via_backend(lesson_id: int, topic_index: int, *,
|
| 53 |
title: Optional[str] = None,
|
| 54 |
topic_name: Optional[str] = None) -> Optional[str]:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
title = title or _resolve_lesson_title_by_id(lesson_id)
|
| 56 |
module_id = str(lesson_id)
|
| 57 |
topic = topic_name or f"Topic {int(topic_index)}"
|
| 58 |
|
| 59 |
+
# Prefer the typed helper that already calls /lesson
|
| 60 |
+
try:
|
| 61 |
+
if hasattr(api, "fetch_lesson_content"):
|
| 62 |
+
return api.fetch_lesson_content(title, module_id, topic)
|
| 63 |
+
except Exception:
|
| 64 |
+
pass
|
| 65 |
+
|
| 66 |
+
# Fallback: call the correct route directly
|
| 67 |
+
resp = _api_post("/lesson", {"lesson": title, "module": module_id, "topic": topic})
|
| 68 |
if isinstance(resp, dict):
|
| 69 |
return resp.get("lesson_content") or resp.get("content")
|
| 70 |
return None
|
| 71 |
|
| 72 |
|
| 73 |
+
|
| 74 |
# --- Load external CSS ---
|
| 75 |
def load_css(file_name):
|
| 76 |
try:
|