コード例 #1
0
ファイル: comment_like.py プロジェクト: gone/Spirit
def like_create(request, comment_id):
    comment = get_object_or_404(Comment.objects.exclude(user=request.user),
                                pk=comment_id)

    if request.method == 'POST':
        form = LikeForm(user=request.user, comment=comment, data=request.POST)

        if form.is_valid():
            like = form.save()
            comment_like_post_create.send(sender=like.__class__,
                                          comment=like.comment)

            if request.is_ajax():
                return json_response({
                    'url_delete': like.get_delete_url(),
                })

            return redirect(
                request.POST.get('next', comment.get_absolute_url()))
    else:
        form = LikeForm()

    return render(request, 'spirit/comment_like/like_create.html', {
        'form': form,
        'comment': comment
    })
コード例 #2
0
ファイル: tests_comment_like.py プロジェクト: gone/Spirit
 def test_like_create(self):
     """
     create like
     """
     form_data = {}
     form = LikeForm(data=form_data)
     form.comment = self.comment
     form.user = self.user
     self.assertEqual(form.is_valid(), True)
コード例 #3
0
ファイル: tests_comment_like.py プロジェクト: gdyuldin/Spirit
 def test_like_create(self):
     """
     create like
     """
     form_data = {}
     form = LikeForm(data=form_data)
     form.comment = self.comment
     form.user = self.user
     self.assertEqual(form.is_valid(), True)
コード例 #4
0
ファイル: tests_comment_like.py プロジェクト: gone/Spirit
 def test_like_create_invalid(self):
     """
     create like twice
     """
     CommentLike.objects.create(user=self.user, comment=self.comment)
     form_data = {}
     form = LikeForm(data=form_data)
     form.comment = self.comment
     form.user = self.user
     self.assertEqual(form.is_valid(), False)
コード例 #5
0
ファイル: tests_comment_like.py プロジェクト: gdyuldin/Spirit
 def test_like_create_invalid(self):
     """
     create like twice
     """
     CommentLike.objects.create(user=self.user, comment=self.comment)
     form_data = {}
     form = LikeForm(data=form_data)
     form.comment = self.comment
     form.user = self.user
     self.assertEqual(form.is_valid(), False)
コード例 #6
0
ファイル: comment_like.py プロジェクト: shtalinberg/Spirit
def like_create(request, comment_id):
    comment = get_object_or_404(Comment.objects.exclude(user=request.user), pk=comment_id)

    if request.method == 'POST':
        form = LikeForm(user=request.user, comment=comment, data=request.POST)

        if form.is_valid():
            like = form.save()
            comment_like_post_create.send(sender=like.__class__, comment=like.comment)

            if request.is_ajax():
                return json_response({'url_delete': like.get_delete_url(), })

            return redirect(request.POST.get('next', comment.get_absolute_url()))
    else:
        form = LikeForm()

    return render(request, 'spirit/comment_like/like_create.html', {'form': form, 'comment': comment})