]> git.parisson.com Git - teleforma.git/commitdiff
add async notif api view
authorGuillaume Pellerin <guillaume.pellerin@parisson.com>
Fri, 6 Feb 2026 22:58:59 +0000 (23:58 +0100)
committerGuillaume Pellerin <guillaume.pellerin@parisson.com>
Fri, 6 Feb 2026 22:58:59 +0000 (23:58 +0100)
teleforma/models/core.py
teleforma/urls.py
teleforma/views/core.py

index 8de0783fcb359261782977b60acb3dd3d3299a01..78a7a466aaeb17d396ede9d558162c0650b196ef 100644 (file)
@@ -497,9 +497,9 @@ class Conference(models.Model):
             else:
                 transport = httpx.HTTPTransport(uds=settings.CHANNEL_URL)
                 async with httpx.AsyncClient(transport=transport) as client:
-                    response = await client.post("http://localhost" + reverse('teleforma-live-conference-notify'),
+                    response = await client.post("http://channels" + reverse('teleforma-live-conference-notify-async'),
                                             data={'id': self.id}, timeout=20.0)
-                    assert response.status_code == 200
+                    #assert response.status_code == 200
 
     def notify_sync(self):
         if self.streaming and not self.notified_live:
index 2fded73d860dc6ccf832a7941379a48022bdbb42..549e6dc9d3dce88614eec9e5609273ffd6a340c0 100644 (file)
@@ -278,15 +278,20 @@ urlpatterns = [
 
     # chat
     path('chat/messages',
-         ChatMessageView.as_view(), name='teleforma-chat-messages'),
+        ChatMessageView.as_view(), name='teleforma-chat-messages'),
+
     # notification
     path('notification',
-         NotificationView.as_view(), name='teleforma-notification'),
+        NotificationView.as_view(), name='teleforma-notification'),
 
     # must be called on channels instance
     path('live_conference_notify',
         LiveConferenceNotify.as_view(), name='teleforma-live-conference-notify'),
 
+    # must be called on channels instance
+    path('live_conference_notify_async',
+        LiveConferenceNotifyAsync.as_view(), name='teleforma-live-conference-notify-async'),
+
     # QUIZ
     url(r'^desk/periods/(?P<period_id>.*)/courses/(?P<course_id>.*)/quiz/(?P<quiz_name>[\w-]+)/$', QuizQuestionView.as_view(), name="teleforma-quiz"),
 ]
index 6366c71f744f79b641f927a669dc289c03e367be..3b82c3c3c6f5faf2b9acd151d953097ef4b931ae 100644 (file)
@@ -1065,6 +1065,42 @@ class LiveConferenceNotify(APIView):
         return Response({'status': 'ok'})
 
 
+class LiveConferenceNotifyAsync(APIView):
+
+    async def post(self, request):
+        """
+        notify users a new live conference is starting
+        """
+        conference_id = request.data.get('id')
+        if not conference_id:
+            raise Exception('No conference id in request')
+        conference = Conference.objects.get(pk=int(conference_id))
+        students = Student.objects.filter(period=conference.period, platform_only=True)
+        text = f"""Une confĂ©rence live "{conference.course.title}" commence"""
+        url = reverse('teleforma-conference-detail', kwargs={'period_id': conference.period.id, 'pk': conference.id})
+
+        # notify students
+        for student in students:
+            try:
+                if student.user:
+                    courses = get_courses(student.user, period=conference.period)
+                    for course in courses:
+                        if conference.course == course['course'] and \
+                                conference.course_type in course['types']:
+                            await notify(student.user, text, url)
+                            logger.info("Student notified: " + student.user.username)
+            except Exception as e:
+                logger.warning("Student NOT notified: " + str(student.id))
+                logger.warning(e)
+                continue
+
+        # notify staff
+        for user in User.objects.filter(is_staff=True):
+            notify(user, text, url)
+
+        return Response({'status': 'ok'})
+
+
 class ProfessorListView(View):
 
     @jsonrpc_method('teleforma.get_professor_list')