|
|
|
@ -167,13 +167,35 @@ def create_course_lesson_from_recording(sender, instance, **kwargs): |
|
|
|
is_active=True |
|
|
|
) |
|
|
|
|
|
|
|
# 3. Determine lesson title: use custom title if available, otherwise Part [n] |
|
|
|
if instance.title and not instance.title.endswith(" - Recording"): |
|
|
|
lesson_title = instance.title |
|
|
|
# 3. Determine lesson title: use custom title or subject (with parts if multiple recordings exist) |
|
|
|
base_title = session.recording_title or session.subject |
|
|
|
|
|
|
|
# Get all recordings for this session, ordered by creation |
|
|
|
recordings = list(LiveSessionRecording.objects.filter(session=session).order_by('created_at', 'id')) |
|
|
|
recordings_count = len(recordings) |
|
|
|
|
|
|
|
if recordings_count <= 1: |
|
|
|
lesson_title = base_title |
|
|
|
else: |
|
|
|
lessons_count = CourseLesson.objects.filter(chapter=chapter).count() |
|
|
|
part_num = lessons_count + 1 |
|
|
|
lesson_title = f"Part {part_num}" |
|
|
|
try: |
|
|
|
current_index = recordings.index(instance) + 1 |
|
|
|
except ValueError: |
|
|
|
current_index = recordings_count |
|
|
|
|
|
|
|
lesson_title = f"{base_title} part {current_index}" |
|
|
|
|
|
|
|
# Retroactively rename the first lesson if this is a subsequent recording |
|
|
|
if current_index > 1: |
|
|
|
first_recording = recordings[0] |
|
|
|
if first_recording.file: |
|
|
|
first_lesson = Lesson.objects.filter(content_file=first_recording.file.name).first() |
|
|
|
if first_lesson: |
|
|
|
first_lesson_title = f"{base_title} part 1" |
|
|
|
first_lesson.title = first_lesson_title |
|
|
|
first_lesson.save(update_fields=['title']) |
|
|
|
|
|
|
|
# Also update corresponding CourseLesson |
|
|
|
CourseLesson.objects.filter(lesson=first_lesson).update(title=first_lesson_title) |
|
|
|
|
|
|
|
# 4. Calculate duration in minutes |
|
|
|
duration_minutes = 0 |
|
|
|
|