Example #1
0
    def post(self, request, *args, **kwargs):
        form = AddCommentForm(request.POST)
        if form.is_valid():
            comment = Comment.objects.get(id=kwargs['comment_id'])
            comment.comment_content = form.data.get('comment_content')
            comment.comment_updatedAt = datetime.now()
            comment.save()

            return HttpResponseRedirect('/category/%s/post/%s/' %
                                        (kwargs['id'], kwargs['pk']))

        else:
            return render(request, 'editComment.html', {
                'form': form,
                'form_error': form.errors
            })
Example #2
0
    def post(self, request, pk, id):
        comment_form = AddCommentForm(request.POST)
        if comment_form.is_valid():
            if request.user.is_authenticated():
                post = Post.objects.get(id=pk)

                comment_form.save(commit=False)
                comment_form.instance.comment_author = request.user
                comment_form.instance.comment_post = post
                comment_form.save()

                return HttpResponseRedirect('/category/%s/post/%s/' % (id, pk))
            else:
                return HttpResponseRedirect('/login/')
        else:
            try:
                post = Post.objects.get(id=pk)
            except Post.DoesNotExist:
                post = None
            return render(
                request, 'post.html', {
                    'post': post,
                    'comment_form': comment_form,
                    'comment_form_error': comment_form.errors
                })
Example #3
0
 def get(self, request, pk, id):
     comment_form = AddCommentForm()
     try:
         post = Post.objects.get(id=pk)
     except Post.DoesNotExist:
         post = None
     return render(
         request, 'post.html', {
             'post': post,
             'comment_form': comment_form,
             'comment_form_error': comment_form.errors
         })
Example #4
0
 def get(self, request, *args, **kwargs):
     if request.user.is_authenticated():
         comment = Comment.objects.get(id=kwargs['comment_id'])
         if request.user.pk == comment.comment_author_id or request.user.is_superuser:
             form = AddCommentForm()
             return render(request, 'editComment.html', {
                 'form': form,
                 'form_error': form.errors
             })
         else:
             return HttpResponseRedirect('/category/%s/post/%s/' %
                                         (kwargs['id'], kwargs['pk']))
     else:
         return HttpResponseRedirect('/login/')