Esempio n. 1
0
def post_detail(request, id_):
    post = Post.objects.get(id=id_)
    rel_post = Post.objects.order_by('-date_posted').filter(
        tag=post.tag, for_cooperative__exact=False).all()
    if request.method == 'POST':
        content = str(request.POST.get('content', False))
        if content:
            comment = Comment()
            comment.author_id = request.user.id
            comment.author_status = author_status(request.user.id)
            comment.date_posted = timezone.now()
            comment.content = content
            comment.post = post
            comment.save()
            return redirect('/post/' + str(id_) + '/')
        else:
            return render(request, 'post/post_detail.html', {
                'post': post,
                'related': rel_post
            })

    return render(request, 'post/post_detail.html', {
        'post': post,
        'related': rel_post
    })
Esempio 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())
Esempio 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())