コード例 #1
0
ファイル: signals.py プロジェクト: pj1031999/projektzapisy
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))
コード例 #2
0
    def test_json_serialization_is_reversible(self):
        before = Notification("123456789", datetime(2019, 5, 5, 20, 35, 0, 0),
                              'aaa{foo}bbb', {'foo': 'bar'})
        serialized = JsonNotificationSerializer().serialize(before)
        after = JsonNotificationSerializer().deserialize(serialized)

        self.assertEqual(before.issued_on, after.issued_on)
        self.assertEqual(before.target, after.target)
        self.assertEqual(before.description_id, after.description_id)
        self.assertEqual(before.description_args, after.description_args)
        self.assertEqual(before.id, after.id)
コード例 #3
0
ファイル: signals.py プロジェクト: pj1031999/projektzapisy
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))
コード例 #4
0
ファイル: signals.py プロジェクト: pj1031999/projektzapisy
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))
コード例 #5
0
ファイル: signals.py プロジェクト: pj1031999/projektzapisy
def notify_board_members_about_voting(sender: Thesis, **kwargs) -> None:
    thesis = kwargs['instance']

    all_voters = get_theses_board()
    accepting_voters = [
        v.owner for v in thesis.thesis_votes.all()
        if v.vote == ThesisVote.ACCEPTED
    ]
    users = [
        voter.user for voter in all_voters if voter not in accepting_voters
    ]
    target = reverse('theses:selected_thesis', args=[thesis.id])

    notify_selected_users(
        users,
        Notification(get_id(), get_time(),
                     NotificationType.THESIS_VOTING_HAS_BEEN_ACTIVATED,
                     {'title': thesis.title}, target))
コード例 #6
0
ファイル: signals.py プロジェクト: pj1031999/projektzapisy
def notify_that_news_was_added(sender: News, **kwargs) -> None:
    news = kwargs['instance']

    # Do not notify about modified news.
    if not kwargs['created']:
        return

    # Do not notify about hidden news.
    if news.category == '-':
        return

    records = set(Employee.get_actives().select_related('user')) | set(
        Student.get_active_students().select_related('user'))
    users = [element.user for element in records]
    target = reverse('news-one', args=[news.id])

    notify_selected_users(
        users,
        Notification(get_id(), get_time(),
                     NotificationType.NEWS_HAS_BEEN_ADDED, {
                         'title': news.title,
                         'contents': news.body
                     }, target))
コード例 #7
0
 def deserialize(self, serialized: str) -> Notification:
     notification_as_dict = json.loads(serialized)
     notification_as_dict['issued_on'] = datetime.strptime(
         notification_as_dict['issued_on'], self.DATE_TIME_FORMAT)
     return Notification(**notification_as_dict)