Update teacher_panel.py
Browse files- teacher_panel.py +10 -12
teacher_panel.py
CHANGED
|
@@ -130,31 +130,29 @@ def teacher_delete_current(
|
|
| 130 |
|
| 131 |
|
| 132 |
def teacher_on_table_select(
|
| 133 |
-
|
| 134 |
) -> Tuple[str, str, str, str]:
|
| 135 |
"""
|
| 136 |
When teacher clicks a row in the Q&A table, load Q/A into textboxes.
|
| 137 |
|
| 138 |
-
|
| 139 |
-
-
|
| 140 |
-
- evt
|
| 141 |
"""
|
| 142 |
try:
|
| 143 |
-
if evt is None or evt.index is None:
|
| 144 |
raise ValueError("Empty select event")
|
| 145 |
|
| 146 |
-
#
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
if idx is None or idx < 0 or idx >= len(table):
|
| 150 |
-
raise IndexError(f"Row index {idx} out of range")
|
| 151 |
-
|
| 152 |
-
row = table[idx] # row should be [id, question, answer]
|
| 153 |
|
| 154 |
current_id = str(row[0]) if len(row) > 0 else ""
|
| 155 |
question = str(row[1]) if len(row) > 1 else ""
|
| 156 |
answer = str(row[2]) if len(row) > 2 else ""
|
| 157 |
|
|
|
|
|
|
|
|
|
|
| 158 |
msg = f"✏️ ເລືອກ Q&A ID {current_id} ສໍາລັບແກ້ໄຂ."
|
| 159 |
except Exception as e: # noqa: BLE001
|
| 160 |
print(f"[WARN] teacher_on_table_select error: {e}")
|
|
|
|
| 130 |
|
| 131 |
|
| 132 |
def teacher_on_table_select(
|
| 133 |
+
evt: gr.SelectData,
|
| 134 |
) -> Tuple[str, str, str, str]:
|
| 135 |
"""
|
| 136 |
When teacher clicks a row in the Q&A table, load Q/A into textboxes.
|
| 137 |
|
| 138 |
+
We only use the SelectData event:
|
| 139 |
+
- evt.index -> (row, col)
|
| 140 |
+
- evt.row_value -> the whole row [id, question, answer]
|
| 141 |
"""
|
| 142 |
try:
|
| 143 |
+
if evt is None or evt.index is None or evt.row_value is None:
|
| 144 |
raise ValueError("Empty select event")
|
| 145 |
|
| 146 |
+
# row_value is already the full row (list-like)
|
| 147 |
+
row = list(evt.row_value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
current_id = str(row[0]) if len(row) > 0 else ""
|
| 150 |
question = str(row[1]) if len(row) > 1 else ""
|
| 151 |
answer = str(row[2]) if len(row) > 2 else ""
|
| 152 |
|
| 153 |
+
if not current_id:
|
| 154 |
+
raise ValueError("Empty ID from selected row")
|
| 155 |
+
|
| 156 |
msg = f"✏️ ເລືອກ Q&A ID {current_id} ສໍາລັບແກ້ໄຂ."
|
| 157 |
except Exception as e: # noqa: BLE001
|
| 158 |
print(f"[WARN] teacher_on_table_select error: {e}")
|