Esempio n. 1
0
 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)
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
 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)
Esempio n. 5
0
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})
Esempio n. 6
0
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
    })
Esempio n. 7
0
def render_like_form(comment, like, next=None):
    form = LikeForm()
    return {'form': form, 'comment_id': comment.pk, 'like': like, 'next': next}