Ejemplo n.º 1
0
def add_comment(request, pk):
    form = CommentForm(request.POST)
    post = get_object_or_404(Post, id=pk)

    if form.is_valid():
        comment = Comment()
        comment.path = []
        comment.comment_post = post
        comment.author = auth.get_user(request)
        comment.content = form.cleaned_data['comment_area']
        comment.save()

        # Django не позволяет увидеть ID комментария по мы не сохраним его,
        # сформируем path после первого сохранения
        # и пересохраним комментарий
        try:
            comment.path.extend(
                Comment.objects.get(
                    id=form.cleaned_data['parent_comment']).path)
            comment.path.append(comment.id)
        except ObjectDoesNotExist:
            comment.path.append(comment.id)

        comment.save()

    return redirect(comment.get_absolute_url())
Ejemplo n.º 2
0
def add_comment(request, article_id):
    form = CommentForm(request.POST)
    post = get_object_or_404(Post, id=article_id)

    if form.is_valid():
        comment = Comment()
        comment.path = []
        comment.post_id = post
        comment.author_id = auth.get_user(request)
        comment.content = form.cleaned_data['comment_area']
        comment.save()

    return redirect(post.get_absolute_url())
Ejemplo n.º 3
0
def add_Comment(request, article_id):
    form = CommentForm(request.POST)
    article = get_object_or_404(Article, id=article_id)
    if form.is_valid():
        comment = Comment()
        comment.path = []
        comment.article_id = article
        comment.author_id = auth.get_user(request)
        comment.content = form.cleaned_data['comment_area']
        comment.save()
        try:
            comment.path.extend(
                Comment.objects.get(
                    id=form.cleaned_data['parent_comment']).path)
            comment.path.append(comment.id)
        except ObjectDoesNotExist:
            comment.path.append(comment.id)
        comment.save()

    return redirect(article.get_absolute_url())