No LaTeX/markdown anywhere students read (seed, import, DB migration 0021, tutor history, frontend guard); quiz of an island is fixed per user again

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-12 12:15:28 +03:30
parent dd10ff83f4
commit e662914efc
11 changed files with 855 additions and 670 deletions

View File

@@ -26,6 +26,8 @@ from django.db import transaction
from rag.services import diagram as diagram_spec
from .plain_math import convert as plain
from .models import Choice, Lesson, Question
VALID_TYPES = {value for value, _ in Question.TYPE_CHOICES}
@@ -44,7 +46,8 @@ def _validate_row(row, index: int) -> dict:
if not isinstance(lesson_id, int):
raise ImportError_(f'{where}: lessonId باید عدد باشد.')
prompt = (row.get('prompt') or '').strip()
# LaTeX/markdown هرگز وارد دیتابیس نمی‌شود (فرانت رندر نمی‌کند): تبدیل در همان ورودی.
prompt = plain((row.get('prompt') or '').strip())
if not prompt:
raise ImportError_(f'{where}: prompt خالی است.')
@@ -55,7 +58,7 @@ def _validate_row(row, index: int) -> dict:
choices = row.get('choices')
if not isinstance(choices, list) or len(choices) < 2:
raise ImportError_(f'{where}: حداقل دو گزینه لازم است.')
choices = [str(c).strip() for c in choices]
choices = [plain(str(c).strip()) for c in choices]
if any(not c for c in choices):
raise ImportError_(f'{where}: گزینه‌ی خالی دارد.')
if len(set(choices)) != len(choices):