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:
# 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"),
]
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')