13,689 new quiz questions in 160 practice islands (grades 3-12), Question.figure, replay rotates the quiz, LaTeX removed from lesson/question text
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -24,6 +24,8 @@ import json
|
||||
|
||||
from django.db import transaction
|
||||
|
||||
from rag.services import diagram as diagram_spec
|
||||
|
||||
from .models import Choice, Lesson, Question
|
||||
|
||||
VALID_TYPES = {value for value, _ in Question.TYPE_CHOICES}
|
||||
@@ -63,12 +65,20 @@ def _validate_row(row, index: int) -> dict:
|
||||
if not isinstance(correct, int) or not (0 <= correct < len(choices)):
|
||||
raise ImportError_(f'{where}: correct باید شمارهی یکی از گزینهها باشد (از صفر).')
|
||||
|
||||
figure = row.get('figure')
|
||||
if figure is not None:
|
||||
# شکلِ نامعتبر بیصدا حذف نمیشود (برخلافِ دستیار): فایلِ محتوا باید خراببودنش را نشان دهد.
|
||||
figure = diagram_spec.validate(figure) if isinstance(figure, dict) else None
|
||||
if figure is None:
|
||||
raise ImportError_(f'{where}: «figure» شکلِ معتبر نیست (قالبِ rag.services.diagram).')
|
||||
|
||||
return {
|
||||
'lesson_id': lesson_id,
|
||||
'prompt': prompt,
|
||||
'type': qtype,
|
||||
'choices': choices,
|
||||
'correct': correct,
|
||||
'figure': figure,
|
||||
}
|
||||
|
||||
|
||||
@@ -135,6 +145,7 @@ def import_questions(
|
||||
continue
|
||||
question = Question.objects.create(
|
||||
lesson_id=row['lesson_id'], type=row['type'], prompt=row['prompt'],
|
||||
figure=row.get('figure'),
|
||||
)
|
||||
Choice.objects.bulk_create([
|
||||
Choice(question=question, value=value, is_correct=(i == row['correct']))
|
||||
@@ -157,13 +168,16 @@ def export_questions(queryset) -> list[dict]:
|
||||
for question in queryset.prefetch_related('choices').select_related('lesson'):
|
||||
choices = list(question.choices.all())
|
||||
correct = next((i for i, c in enumerate(choices) if c.is_correct), 0)
|
||||
out.append({
|
||||
row = {
|
||||
'lessonId': question.lesson_id,
|
||||
'prompt': question.prompt,
|
||||
'type': question.type,
|
||||
'choices': [c.value for c in choices],
|
||||
'correct': correct,
|
||||
})
|
||||
}
|
||||
if question.figure:
|
||||
row['figure'] = question.figure
|
||||
out.append(row)
|
||||
return out
|
||||
|
||||
|
||||
@@ -189,13 +203,16 @@ def export_questions_by_path(queryset) -> list[dict]:
|
||||
correct = next((i for i, c in enumerate(choices) if c.is_correct), 0)
|
||||
lesson = question.lesson
|
||||
node = lesson.node
|
||||
out.append({
|
||||
row = {
|
||||
'path': [node.unit.grade.title, node.unit.title, node.title, lesson.title],
|
||||
'prompt': question.prompt,
|
||||
'type': question.type,
|
||||
'choices': [c.value for c in choices],
|
||||
'correct': correct,
|
||||
})
|
||||
}
|
||||
if question.figure:
|
||||
row['figure'] = question.figure
|
||||
out.append(row)
|
||||
return out
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user