Files
MathApp/content/management/commands/split_long_nodes.py
Zareian 8cb1ecb85e Subjects per grade (math, calculus, geometry, stats, discrete), 5 new textbooks, 202 new islands, long islands split, hand-written figures and lesson texts for the new books
- content.Subject + Unit.subject, /api/home?subject=, tutor grounded in the chosen book
- 5 new books ingested; ~1150 hand-written questions, islands named by hand
- node_split: islands over 7 lessons split into parts of <=6 (lesson ids and progress kept)
- Lesson.figures hand-authored and visually checked for 653 lessons of the new books;
  gen_lesson_figures got --subject and survives network errors
- seed files re-exported

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-12 05:35:18 +03:30

37 lines
2.0 KiB
Python

"""
جزیره‌های بلند را به جزیره‌های حداکثر ۶ درسی می‌شکند (منطق در `content/node_split.py`).
python manage.py split_long_nodes --grade 8 --dry-run
python manage.py split_long_nodes --grade 4 --grade 5
پایه‌های ۳ تا ۱۲ را migrationِ 0018 یک بار شکسته است؛ این دستور برای پایه‌ی تازه یا آستانه‌ی دیگر است و اجرای
دوباره‌اش بی‌اثر. بعد از اجرا فایل‌های seed را دوباره بسازید (`seed_content --export`)، وگرنه
`seed_content` جزیره‌های بلندِ قدیمی را کنارِ بخش‌های تازه دوباره می‌سازد.
"""
from django.core.management.base import BaseCommand
from django.db import transaction
from content.models import Lesson, Node, NodeProgress, Unit, UserNodeCompletion
from content.node_split import split_long_nodes
class Command(BaseCommand):
help = 'شکستنِ جزیره‌های بلند به جزیره‌های کوتاه‌تر، با حفظِ پیشرفتِ کاربران.'
def add_arguments(self, parser):
parser.add_argument('--grade', type=int, action='append', required=True,
help='شماره‌ی پایه؛ چند بار قابلِ تکرار.')
parser.add_argument('--max-lessons', type=int, default=7)
parser.add_argument('--part-cap', type=int, default=6)
parser.add_argument('--dry-run', action='store_true')
def handle(self, *args, **opts):
units = Unit.objects.filter(grade__number__in=opts['grade']).order_by('id')
with transaction.atomic():
counts = split_long_nodes(
Node=Node, Lesson=Lesson, UserNodeCompletion=UserNodeCompletion,
NodeProgress=NodeProgress, units=units,
max_lessons=opts['max_lessons'], part_cap=opts['part_cap'], dry_run=opts['dry_run'],
)
self.stdout.write(f"{'(dry-run) ' if opts['dry_run'] else ''}{counts}")