fix test editor UI and test completition UI
This commit is contained in:
@@ -46,7 +46,13 @@ def _to_uuid(val) -> _uuid.UUID | None:
|
||||
|
||||
# ─── load questions (shared) ─────────────────────────────────────────────────
|
||||
|
||||
def load_questions_for_version(session: Session, test_version_id, *, include_correct: bool) -> list[dict]:
|
||||
def load_questions_for_version(
|
||||
session: Session,
|
||||
test_version_id,
|
||||
*,
|
||||
include_correct: bool,
|
||||
include_hints: bool = False,
|
||||
) -> list[dict]:
|
||||
vid = _to_uuid(test_version_id)
|
||||
if vid is None:
|
||||
return []
|
||||
@@ -65,13 +71,17 @@ def load_questions_for_version(session: Session, test_version_id, *, include_cor
|
||||
if include_correct:
|
||||
base['isCorrect'] = bool(o.is_correct)
|
||||
options.append(base)
|
||||
out.append({
|
||||
item = {
|
||||
'id': str(q.id),
|
||||
'text': q.text,
|
||||
'questionOrder': q.question_order,
|
||||
'hasMultipleAnswers': bool(q.has_multiple_answers),
|
||||
'options': options,
|
||||
})
|
||||
}
|
||||
if include_hints:
|
||||
hint = (q.ai_hint or '').strip()
|
||||
item['aiHint'] = hint or None
|
||||
out.append(item)
|
||||
return out
|
||||
|
||||
|
||||
@@ -275,7 +285,9 @@ def build_review_from_db(session: Session, attempt_id: str) -> dict:
|
||||
raise HttpError(400, 'Попытка не завершена.')
|
||||
|
||||
test = attempt.test_version.test
|
||||
questions = load_questions_for_version(session, attempt.test_version_id, include_correct=True)
|
||||
questions = load_questions_for_version(
|
||||
session, attempt.test_version_id, include_correct=True, include_hints=True
|
||||
)
|
||||
|
||||
sel_by_q: dict[str, list[str]] = {
|
||||
str(ua.question_id): [str(x) for x in (ua.selected_options or [])]
|
||||
@@ -294,6 +306,7 @@ def build_review_from_db(session: Session, attempt_id: str) -> dict:
|
||||
'id': q['id'],
|
||||
'text': q['text'],
|
||||
'hasMultipleAnswers': q['hasMultipleAnswers'],
|
||||
'aiHint': q.get('aiHint'),
|
||||
'isUserCorrect': _same_selection(selected, correct),
|
||||
'options': [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user