def notify_that_group_was_added_in_course(sender: Group, **kwargs) -> None: group = kwargs['instance'] if not kwargs['created']: return course_groups = Group.objects.filter(course=group.course) course_name = group.course.name target = reverse(course_view, args=[group.course.slug]) if group.teacher is not None: teacher = group.teacher.user notify_user( teacher, Notification(get_id(), get_time(), NotificationType.ASSIGNED_TO_NEW_GROUP_AS_A_TEACHER, {'course_name': course_name}, target)) enrolled_or_queued = [RecordStatus.ENROLLED, RecordStatus.QUEUED] records = Record.objects.filter( group__in=course_groups, status__in=enrolled_or_queued).select_related('student', 'student__user') users = {element.student.user for element in records} notify_selected_users( users, Notification(get_id(), get_time(), NotificationType.ADDED_NEW_GROUP, { 'course_name': course_name, 'teacher': group.get_teacher_full_name() }, target))
def notify_that_student_was_pulled_from_queue(sender: Record, **kwargs) -> None: group = kwargs['instance'] target = reverse(course_view, args=[group.course.slug]) notify_user( kwargs['user'], Notification( get_id(), get_time(), NotificationType.PULLED_FROM_QUEUE, { 'course_name': group.course.name, 'teacher': group.get_teacher_full_name(), 'type': group.get_type_display(), }, target))
def notify_that_teacher_was_changed(sender: Group, **kwargs) -> None: group = kwargs['instance'] if group.teacher is not None: teacher = group.teacher.user course_name = group.course.name target = reverse(course_view, args=[group.course.slug]) notify_user( teacher, Notification(get_id(), get_time(), NotificationType.ASSIGNED_TO_NEW_GROUP_AS_A_TEACHER, {'course_name': course_name}, target)) queued_users = User.objects.filter( student__record__group=group, student__record__status=RecordStatus.QUEUED) enrolled_users = User.objects.filter( student__record__group=group, student__record__status=RecordStatus.ENROLLED) notify_selected_users( queued_users, Notification( get_id(), get_time(), NotificationType.TEACHER_HAS_BEEN_CHANGED_QUEUED, { 'course_name': course_name, 'teacher': group.get_teacher_full_name(), 'type': group.get_type_display(), }, target)) notify_selected_users( enrolled_users, Notification( get_id(), get_time(), NotificationType.TEACHER_HAS_BEEN_CHANGED_ENROLLED, { 'course_name': course_name, 'teacher': teacher.get_full_name(), 'type': group.get_type_display(), }, target))