Browse Source

set livesession recording view

master
Mohsen Taba 1 month ago
parent
commit
d6b3917f7e
  1. 34
      apps/course/signals.py
  2. 9
      apps/course/views/live_session.py

34
apps/course/signals.py

@ -167,13 +167,35 @@ def create_course_lesson_from_recording(sender, instance, **kwargs):
is_active=True 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: 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 # 4. Calculate duration in minutes
duration_minutes = 0 duration_minutes = 0

9
apps/course/views/live_session.py

@ -731,8 +731,8 @@ class CourseLiveSessionRecordedFileAPIView(GenericAPIView):
class CourseLiveSessionSetRecordingTitleAPIView(GenericAPIView): class CourseLiveSessionSetRecordingTitleAPIView(GenericAPIView):
permission_classes = [IsAuthenticated]
authentication_classes = [TokenAuthentication]
permission_classes = [AllowAny]
authentication_classes = []
@swagger_auto_schema( @swagger_auto_schema(
operation_description="Set the recording title for the active live session", operation_description="Set the recording title for the active live session",
@ -763,13 +763,8 @@ class CourseLiveSessionSetRecordingTitleAPIView(GenericAPIView):
except CourseLiveSession.DoesNotExist: except CourseLiveSession.DoesNotExist:
raise AppAPIException({'message': 'Active session not found.'}, status_code=status.HTTP_404_NOT_FOUND) raise AppAPIException({'message': 'Active session not found.'}, status_code=status.HTTP_404_NOT_FOUND)
# Check if user has permission to manage course associated with session
if not request.user.can_manage_course(session.course):
raise AppAPIException({'message': 'Permission denied.'}, status_code=status.HTTP_403_FORBIDDEN)
session.recording_title = title.strip() session.recording_title = title.strip()
session.save(update_fields=['recording_title', 'updated_at']) session.save(update_fields=['recording_title', 'updated_at'])
logger.info(f"[LiveSession Title] Set recording title for room_id={room_id} to '{title}'") logger.info(f"[LiveSession Title] Set recording title for room_id={room_id} to '{title}'")
return Response({'success': True, 'message': 'Recording title updated successfully.'}, status=status.HTTP_200_OK) return Response({'success': True, 'message': 'Recording title updated successfully.'}, status=status.HTTP_200_OK)
Loading…
Cancel
Save