Exemple #1
0
def mark_notifications_as_read(request):
    """
    Mark the notifications of the current user as read.
    If a notification is linked to a comment, the topic
    or content associed is also marked as read.
    Note that notifications for private messages are not concerned.
    """

    content_type = ContentType.objects.get_for_model(PrivateTopic)
    notifications = Notification.objects.get_unread_notifications_of(request.user) \
        .exclude(subscription__content_type=content_type) \

    for notification in notifications:
        if isinstance(notification.content_object, Post):
            mark_topic_read(notification.content_object.topic, request.user)
        if isinstance(notification.content_object, ContentReaction):
            mark_content_read(notification.content_object.related_content,
                              request.user)

    notifications.update(is_read=True)

    messages.success(request,
                     _('Vos notifications ont bien été marquées comme lues.'))

    return redirect(reverse('notification-list'))
Exemple #2
0
def mark_notifications_as_read(request):
    """
    Mark the notifications of the current user as read.
    If a notification is linked to a comment, the topic
    or content associed is also marked as read.
    Note that notifications for private messages are not concerned.
    """

    content_type = ContentType.objects.get_for_model(PrivateTopic)
    notifications = Notification.objects.get_unread_notifications_of(request.user) \
        .exclude(subscription__content_type=content_type) \

    for notification in notifications:
        if isinstance(notification.content_object, Post):
            mark_topic_read(notification.content_object.topic, request.user)
        if isinstance(notification.content_object, ContentReaction):
            mark_content_read(notification.content_object.related_content, request.user)

    notifications.update(is_read=True)

    messages.success(request, _('Vos notifications ont bien été marquées comme lues.'))

    return redirect(reverse('notification-list'))