コード例 #1
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)

        context.update({
            'topic':
            self.object,
            'posts':
            self.build_list_with_previous_item(context['object_list']),
            'last_post_pk':
            self.object.last_message.pk,
            'form':
            form,
            'form_move':
            MoveTopicForm(topic=self.object),
        })
        reaction_ids = [post.pk for post in context['posts']]
        context["user_dislike"] = CommentDislike.objects\
            .select_related('comment')\
            .filter(user__pk=self.request.user.pk, comments__pk__in=reaction_ids)\
            .values_list('pk', flat=True)
        context["user_like"] = CommentLike.objects\
            .select_related('comment')\
            .filter(user__pk=self.request.user.pk, comments__pk__in=reaction_ids)\
            .values_list('pk', flat=True)
        context["is_staff"] = self.request.user.has_perm('forum.change_topic')
        if self.request.user.is_authenticated():
            if never_read(self.object):
                mark_read(self.object)
        return context
コード例 #2
0
ファイル: views.py プロジェクト: philippemilink/zds-site
    def get_context_data(self, **kwargs):
        context = super().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["has_token"] = self.request.user.profile.github_token != ""
            context["repositories"] = settings.ZDS_APP["github_projects"][
                "repositories"]

        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:
            if len(posts) > 0:
                signals.post_read.send(sender=posts[0].__class__,
                                       instances=posts,
                                       user=self.request.user)
            if not self.object.is_read:
                mark_read(self.object)
        return context
コード例 #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