How to use the spirit.comment.models.Comment.objects.filter function in spirit

To help you get started, we’ve selected a few spirit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nitely / Spirit / spirit / topic / moderate / tests.py View on Github external
"""
        utils.login(self)
        self.user.st.is_moderator = True
        self.user.save()

        category = utils.create_category()
        topic = utils.create_topic(category)
        form_data = {}
        response = self.client.post(
            reverse('spirit:topic:moderate:pin', kwargs={'pk': topic.pk, }),
            form_data)
        expected_url = topic.get_absolute_url()
        self.assertRedirects(response, expected_url, status_code=302)
        self.assertTrue(Topic.objects.get(pk=topic.pk).is_pinned)
        self.assertEqual(
            len(Comment.objects.filter(user=self.user, topic=topic, action=PINNED)),
            1)
github nitely / Spirit / spirit / comment / tests.py View on Github external
"""
        utils.login(self)
        self.user.st.is_moderator = True
        self.user.save()
        Topic.objects.filter(pk=self.topic.pk).update(comment_count=2)
        comment = utils.create_comment(user=self.user, topic=self.topic)
        comment2 = utils.create_comment(user=self.user, topic=self.topic)
        to_topic = utils.create_topic(category=self.category)
        form_data = {'topic': to_topic.pk,
                     'comments': [comment.pk, comment2.pk], }
        response = self.client.post(reverse('spirit:comment:move', kwargs={'topic_id': self.topic.pk, }),
                                    form_data)
        expected_url = self.topic.get_absolute_url()
        self.assertRedirects(response, expected_url, status_code=302)
        self.assertEqual(Comment.objects.filter(topic=to_topic.pk).count(), 2)
        self.assertEqual(Comment.objects.filter(topic=self.topic.pk).count(), 0)
        self.assertEqual(Topic.objects.get(pk=self.topic.pk).comment_count, 0)
github nitely / Spirit / spirit / comment / tests.py View on Github external
def test_comment_create_moderation_action(self):
        """
        Create comment that tells what moderation action was made
        """
        Comment.create_moderation_action(user=self.user, topic=self.topic, action=1)
        self.assertEqual(Comment.objects.filter(user=self.user, topic=self.topic, action=1).count(), 1)
github nitely / Spirit / spirit / comment / tests.py View on Github external
def test_comments_move(self):
        comment = utils.create_comment(user=self.user, topic=self.topic)
        comment2 = utils.create_comment(user=self.user, topic=self.topic)
        to_topic = utils.create_topic(category=self.category)
        form_data = {'topic': to_topic.pk,
                     'comments': [comment.pk, comment2.pk], }
        form = CommentMoveForm(topic=self.topic, data=form_data)
        self.assertEqual(form.is_valid(), True)
        self.assertEqual(form.save(), list(Comment.objects.filter(topic=to_topic)))
github nitely / Spirit / spirit / user / views.py View on Github external
def likes(request, pk, slug):
    # todo: test with_polls!
    user_comments = (
        Comment.objects
        .filter(comment_likes__user_id=pk)
        .visible()
        .with_polls(user=request.user)
        .select_related('topic')
        .order_by('-comment_likes__date', '-pk'))

    return _activity(
        request, pk, slug,
        queryset=user_comments,
        template='spirit/user/profile_likes.html',
        reverse_to='spirit:user:likes',
        context_name='comments',
        per_page=config.comments_per_page)
github nitely / Spirit / spirit / comment / models.py View on Github external
def decrease_likes_count(self, acting_user):
        Comment.objects\
            .filter(pk=self.pk)\
            .update(likes_count=F('likes_count') - 1)
        if not self.topic.category.is_private:
            self.user.st.decrease_received_likes_count()
            acting_user.st.decrease_given_likes_count()
github nitely / Spirit / spirit / comment / views.py View on Github external
def delete(request, pk, remove=True):
    comment = get_object_or_404(Comment, pk=pk)

    if request.method == 'POST':
        (Comment.objects
         .filter(pk=pk)
         .update(is_removed=remove))

        return redirect(request.GET.get('next', comment.get_absolute_url()))

    context = {'comment': comment}

    return render(request, 'spirit/comment/moderate.html', context)