Update teacher_panel.py
Browse files- teacher_panel.py +19 -25
teacher_panel.py
CHANGED
|
@@ -21,10 +21,6 @@ def _table() -> List[List[str]]:
|
|
| 21 |
def teacher_save_add_overwrite(
|
| 22 |
question: str, answer: str, current_id: str
|
| 23 |
) -> Tuple[str, str, str, List[List[str]], str]:
|
| 24 |
-
"""
|
| 25 |
-
Add a new manual Q&A or overwrite existing one
|
| 26 |
-
with the same normalized question.
|
| 27 |
-
"""
|
| 28 |
question = (question or "").strip()
|
| 29 |
answer = (answer or "").strip()
|
| 30 |
current_id = current_id or ""
|
|
@@ -37,14 +33,12 @@ def teacher_save_add_overwrite(
|
|
| 37 |
entry = qa_store.MANUAL_QA_INDEX.get(norm_q)
|
| 38 |
|
| 39 |
if entry:
|
| 40 |
-
# overwrite existing manual Q&A
|
| 41 |
entry["q"] = question
|
| 42 |
entry["a"] = answer
|
| 43 |
entry["norm_q"] = norm_q
|
| 44 |
current_id = entry["id"]
|
| 45 |
-
|
| 46 |
else:
|
| 47 |
-
# create new entry
|
| 48 |
new_id = generate_new_manual_id()
|
| 49 |
entry = {
|
| 50 |
"id": new_id,
|
|
@@ -55,21 +49,21 @@ def teacher_save_add_overwrite(
|
|
| 55 |
qa_store.MANUAL_QA_LIST.append(entry)
|
| 56 |
qa_store.MANUAL_QA_INDEX[norm_q] = entry
|
| 57 |
current_id = new_id
|
| 58 |
-
|
| 59 |
|
| 60 |
-
save_manual_qa_file()
|
| 61 |
-
rebuild_combined_qa()
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
return question, answer, current_id, _table(),
|
| 65 |
|
| 66 |
|
| 67 |
def teacher_update_current(
|
| 68 |
question: str, answer: str, current_id: str
|
| 69 |
) -> Tuple[str, str, str, List[List[str]], str]:
|
| 70 |
-
"""
|
| 71 |
-
Update the currently selected manual Q&A by id.
|
| 72 |
-
"""
|
| 73 |
question = (question or "").strip()
|
| 74 |
answer = (answer or "").strip()
|
| 75 |
current_id = current_id or ""
|
|
@@ -88,7 +82,6 @@ def teacher_update_current(
|
|
| 88 |
current_id = ""
|
| 89 |
return question, answer, current_id, _table(), msg
|
| 90 |
|
| 91 |
-
# remove old index
|
| 92 |
qa_store.MANUAL_QA_INDEX.pop(entry["norm_q"], None)
|
| 93 |
|
| 94 |
new_norm = normalize_question(question)
|
|
@@ -99,18 +92,17 @@ def teacher_update_current(
|
|
| 99 |
|
| 100 |
save_manual_qa_file()
|
| 101 |
rebuild_combined_qa()
|
| 102 |
-
sync_upload_manual_qa() # <--- Upload to Cloud (NEW)
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
|
| 108 |
def teacher_delete_current(
|
| 109 |
current_id: str,
|
| 110 |
) -> Tuple[str, str, str, List[List[str]], str]:
|
| 111 |
-
"""
|
| 112 |
-
Delete the currently selected manual Q&A.
|
| 113 |
-
"""
|
| 114 |
current_id = current_id or ""
|
| 115 |
|
| 116 |
if not current_id:
|
|
@@ -127,10 +119,12 @@ def teacher_delete_current(
|
|
| 127 |
|
| 128 |
save_manual_qa_file()
|
| 129 |
rebuild_combined_qa()
|
| 130 |
-
sync_upload_manual_qa() # <--- Upload to Cloud (NEW)
|
| 131 |
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
|
| 136 |
def teacher_on_table_select(
|
|
|
|
| 21 |
def teacher_save_add_overwrite(
|
| 22 |
question: str, answer: str, current_id: str
|
| 23 |
) -> Tuple[str, str, str, List[List[str]], str]:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
question = (question or "").strip()
|
| 25 |
answer = (answer or "").strip()
|
| 26 |
current_id = current_id or ""
|
|
|
|
| 33 |
entry = qa_store.MANUAL_QA_INDEX.get(norm_q)
|
| 34 |
|
| 35 |
if entry:
|
|
|
|
| 36 |
entry["q"] = question
|
| 37 |
entry["a"] = answer
|
| 38 |
entry["norm_q"] = norm_q
|
| 39 |
current_id = entry["id"]
|
| 40 |
+
local_msg = "✅ ອັບເດດ Q&A ແລ້ວ."
|
| 41 |
else:
|
|
|
|
| 42 |
new_id = generate_new_manual_id()
|
| 43 |
entry = {
|
| 44 |
"id": new_id,
|
|
|
|
| 49 |
qa_store.MANUAL_QA_LIST.append(entry)
|
| 50 |
qa_store.MANUAL_QA_INDEX[norm_q] = entry
|
| 51 |
current_id = new_id
|
| 52 |
+
local_msg = "✅ ບັນທຶກ Q&A ໃໝ່ແລ້ວ."
|
| 53 |
|
| 54 |
+
save_manual_qa_file()
|
| 55 |
+
rebuild_combined_qa()
|
| 56 |
+
|
| 57 |
+
# 👇 NEW: Capture the upload status and add it to the message
|
| 58 |
+
cloud_status = sync_upload_manual_qa()
|
| 59 |
+
final_msg = f"{local_msg} ({cloud_status})"
|
| 60 |
|
| 61 |
+
return question, answer, current_id, _table(), final_msg
|
| 62 |
|
| 63 |
|
| 64 |
def teacher_update_current(
|
| 65 |
question: str, answer: str, current_id: str
|
| 66 |
) -> Tuple[str, str, str, List[List[str]], str]:
|
|
|
|
|
|
|
|
|
|
| 67 |
question = (question or "").strip()
|
| 68 |
answer = (answer or "").strip()
|
| 69 |
current_id = current_id or ""
|
|
|
|
| 82 |
current_id = ""
|
| 83 |
return question, answer, current_id, _table(), msg
|
| 84 |
|
|
|
|
| 85 |
qa_store.MANUAL_QA_INDEX.pop(entry["norm_q"], None)
|
| 86 |
|
| 87 |
new_norm = normalize_question(question)
|
|
|
|
| 92 |
|
| 93 |
save_manual_qa_file()
|
| 94 |
rebuild_combined_qa()
|
|
|
|
| 95 |
|
| 96 |
+
# 👇 NEW: Capture the upload status
|
| 97 |
+
cloud_status = sync_upload_manual_qa()
|
| 98 |
+
final_msg = f"✅ ແກ້ໄຂ Q&A ສໍາເລັດ. ({cloud_status})"
|
| 99 |
+
|
| 100 |
+
return question, answer, current_id, _table(), final_msg
|
| 101 |
|
| 102 |
|
| 103 |
def teacher_delete_current(
|
| 104 |
current_id: str,
|
| 105 |
) -> Tuple[str, str, str, List[List[str]], str]:
|
|
|
|
|
|
|
|
|
|
| 106 |
current_id = current_id or ""
|
| 107 |
|
| 108 |
if not current_id:
|
|
|
|
| 119 |
|
| 120 |
save_manual_qa_file()
|
| 121 |
rebuild_combined_qa()
|
|
|
|
| 122 |
|
| 123 |
+
# 👇 NEW: Capture the upload status
|
| 124 |
+
cloud_status = sync_upload_manual_qa()
|
| 125 |
+
final_msg = f"🗑️ ລຶບ Q&A ສໍາເລັດ. ({cloud_status})"
|
| 126 |
+
|
| 127 |
+
return "", "", "", _table(), final_msg
|
| 128 |
|
| 129 |
|
| 130 |
def teacher_on_table_select(
|