Esempio n. 1
0
    def test_mark_notifications_as_read(self):
        category = CategoryFactory(position=1)
        forum = ForumFactory(category=category, position_in_category=1)
        topic = TopicFactory(forum=forum, author=self.user1)
        PostFactory(topic=topic, author=self.user1, position=1)
        PostFactory(topic=topic, author=self.user2, position=2)

        self.assertTrue(
            self.client.login(username=self.user1.username,
                              password='******'))

        notifications = Notification.objects.get_unread_notifications_of(
            self.user1)
        self.assertEqual(1, len(notifications))

        self.assertFalse(is_read(topic, self.user1))

        result = self.client.post(reverse('mark-notifications-as-read'),
                                  follow=False)
        self.assertEqual(result.status_code, 302)

        notifications = Notification.objects.get_unread_notifications_of(
            self.user1)
        self.assertEqual(0, len(notifications))

        self.assertTrue(is_read(topic, self.user1))
Esempio n. 2
0
    def test_mark_notifications_as_read(self):
        category = CategoryFactory(position=1)
        forum = ForumFactory(category=category, position_in_category=1)
        topic = TopicFactory(forum=forum, author=self.user1)
        PostFactory(topic=topic, author=self.user1, position=1)
        PostFactory(topic=topic, author=self.user2, position=2)

        self.assertTrue(self.client.login(username=self.user1.username, password='******'))

        notifications = Notification.objects.get_unread_notifications_of(self.user1)
        self.assertEqual(1, len(notifications))

        self.assertFalse(is_read(topic, self.user1))

        result = self.client.post(
            reverse('mark-notifications-as-read'),
            follow=False)
        self.assertEqual(result.status_code, 302)

        notifications = Notification.objects.get_unread_notifications_of(self.user1)
        self.assertEqual(0, len(notifications))

        self.assertTrue(is_read(topic, self.user1))
Esempio n. 3
0
    def get_context_data(self, **kwargs):
        context = super(TopicPostsListView, self).get_context_data(**kwargs)
        form = PostForm(self.object, self.request.user)
        form.helper.form_action = reverse('post-new') + '?sujet=' + str(
            self.object.pk)

        posts = self.build_list_with_previous_item(context['object_list'])
        context.update({
            'topic': self.object,
            'posts': posts,
            'last_post_pk': self.object.last_message.pk,
            'form': form,
            'form_move': MoveTopicForm(topic=self.object),
        })

        votes = CommentVote.objects.filter(user_id=self.request.user.pk,
                                           comment__in=context['posts']).all()
        context['user_like'] = [
            vote.comment_id for vote in votes if vote.positive
        ]
        context['user_dislike'] = [
            vote.comment_id for vote in votes if not vote.positive
        ]
        context['is_staff'] = self.request.user.has_perm('forum.change_topic')
        context['isantispam'] = self.object.antispam()
        context[
            'subscriber_count'] = TopicAnswerSubscription.objects.get_subscriptions(
                self.object).count()
        if hasattr(self.request.user, 'profile'):
            context['is_dev'] = self.request.user.profile.is_dev()
            context['tags'] = settings.ZDS_APP['site']['repository']['tags']
            context['has_token'] = self.request.user.profile.github_token != ''

        if self.request.user.has_perm('forum.change_topic'):
            context['user_can_modify'] = [post.pk for post in context['posts']]
        else:
            context['user_can_modify'] = [
                post.pk for post in context['posts']
                if post.author == self.request.user
            ]

        if self.request.user.is_authenticated():
            for post in posts:
                signals.content_read.send(sender=post.__class__,
                                          instance=post,
                                          user=self.request.user)
            if not is_read(self.object):
                mark_read(self.object)
        return context
Esempio n. 4
0
    def get_context_data(self, **kwargs):
        context = super(TopicPostsListView, self).get_context_data(**kwargs)
        form = PostForm(self.object, self.request.user)
        form.helper.form_action = reverse("post-new") + "?sujet=" + str(
            self.object.pk)

        posts = self.build_list_with_previous_item(context["object_list"])
        context.update({
            "topic": self.object,
            "posts": posts,
            "last_post_pk": self.object.last_message.pk,
            "form": form,
            "form_move": MoveTopicForm(topic=self.object),
        })

        votes = CommentVote.objects.filter(user_id=self.request.user.pk,
                                           comment__in=context["posts"]).all()
        context["user_like"] = [
            vote.comment_id for vote in votes if vote.positive
        ]
        context["user_dislike"] = [
            vote.comment_id for vote in votes if not vote.positive
        ]
        context["is_staff"] = self.request.user.has_perm("forum.change_topic")
        context["is_antispam"] = self.object.antispam()
        context[
            "subscriber_count"] = TopicAnswerSubscription.objects.get_subscriptions(
                self.object).count()
        if hasattr(self.request.user, "profile"):
            context["is_dev"] = self.request.user.profile.is_dev()
            context["tags"] = settings.ZDS_APP["site"]["repository"]["tags"]
            context["has_token"] = self.request.user.profile.github_token != ""

        if self.request.user.has_perm("forum.change_topic"):
            context["user_can_modify"] = [post.pk for post in context["posts"]]
        else:
            context["user_can_modify"] = [
                post.pk for post in context["posts"]
                if post.author == self.request.user
            ]

        if self.request.user.is_authenticated:
            for post in posts:
                signals.post_read.send(sender=post.__class__,
                                       instance=post,
                                       user=self.request.user)
            if not is_read(self.object):
                mark_read(self.object)
        return context
Esempio n. 5
0
    def get_context_data(self, **kwargs):
        context = super(TopicPostsListView, self).get_context_data(**kwargs)
        form = PostForm(self.object, self.request.user)
        form.helper.form_action = reverse('post-new') + '?sujet=' + str(self.object.pk)

        posts = self.build_list_with_previous_item(context['object_list'])
        context.update({
            'topic': self.object,
            'posts': posts,
            'last_post_pk': self.object.last_message.pk,
            'form': form,
            'form_move': MoveTopicForm(topic=self.object),
        })

        votes = CommentVote.objects.filter(user_id=self.request.user.pk, comment__in=context['posts']).all()
        context['user_like'] = [vote.comment_id for vote in votes if vote.positive]
        context['user_dislike'] = [vote.comment_id for vote in votes if not vote.positive]
        context['is_staff'] = self.request.user.has_perm('forum.change_topic')
        context['is_antispam'] = self.object.antispam()
        context['subscriber_count'] = TopicAnswerSubscription.objects.get_subscriptions(self.object).count()
        if hasattr(self.request.user, 'profile'):
            context['is_dev'] = self.request.user.profile.is_dev()
            context['tags'] = settings.ZDS_APP['site']['repository']['tags']
            context['has_token'] = self.request.user.profile.github_token != ''

        if self.request.user.has_perm('forum.change_topic'):
            context['user_can_modify'] = [post.pk for post in context['posts']]
        else:
            context['user_can_modify'] = [post.pk for post in context['posts'] if post.author == self.request.user]

        if self.request.user.is_authenticated():
            for post in posts:
                signals.content_read.send(sender=post.__class__, instance=post, user=self.request.user)
            if not is_read(self.object):
                mark_read(self.object)
        return context