Example #1
0
def notify_that_student_was_not_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.NOT_PULLED_FROM_QUEUE, {
                'course_name': group.course.name,
                'teacher': group.get_teacher_full_name(),
                'type': group.get_type_display(),
                'reason': kwargs['reason']
            }, target))
Example #2
0
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))
Example #3
0
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))
Example #4
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)