Browse Source

creating online class based on new name format

master
Mohsen Taba 2 months ago
parent
commit
76810cf1d7
  1. 29
      apps/course/views/live_session.py

29
apps/course/views/live_session.py

@ -21,6 +21,31 @@ from django.conf import settings
logger = logging.getLogger(__name__)
def get_live_session_subject(course):
title = ""
course_title = course.title
if isinstance(course_title, list):
for tr in course_title:
if isinstance(tr, dict) and tr.get('language_code') == 'en':
val = tr.get('title') or tr.get('text') or tr.get('value') or tr.get('name')
if val:
title = str(val).strip()
break
if not title:
for tr in course_title:
if isinstance(tr, dict) and tr.get('language_code') == 'ru':
val = tr.get('title') or tr.get('text') or tr.get('value') or tr.get('name')
if val:
title = str(val).strip()
break
if not title:
from apps.course.models.course import extract_text_from_json
title = extract_text_from_json(course_title)
if not title:
title = "Course"
return f"{title} Live Session"
class CourseLiveSessionRoomCreateAPIView(GenericAPIView):
permission_classes = [IsAuthenticated]
authentication_classes = [TokenAuthentication]
@ -51,7 +76,7 @@ class CourseLiveSessionRoomCreateAPIView(GenericAPIView):
raise AppAPIException({'message': 'Permission denied'}, status_code=403)
# 2. Setup ID and Metadata
subject = f"{course.title} Live Session"
subject = get_live_session_subject(course)
# 3. Database Logic - Check FIRST before calling PlugNMeet
session = CourseLiveSession.objects.filter(
@ -551,7 +576,7 @@ class CourseLiveSessionTokenAPIView(GenericAPIView):
Raises:
PlugNMeetError: If room creation fails
"""
subject = session.subject or f"{course.title} Live Session"
subject = session.subject or get_live_session_subject(course)
room_id = session.room_id
metadata = self._build_metadata(subject)

Loading…
Cancel
Save