示例#1
0
def comment_add(request,id):
    article = get_object_or_404(Article,pk=id)
    #add comment
    if request.method=='POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            #comment_parent=Comment(id=cd["comment_parent_id"]),
            post = Comment(
                article=Article(id=id),
                user = User(id=cd["user_id"]),
                email = cd["email"],
                author = cd["author"],
                content = cd["content"]
            )
            if cd["comment_parent_id"] != None:
                post.comment_parent = Comment(id=cd["comment_parent_id"])

            post.save()
            article.comment_count+=1
            article.save()

        print("%r" % form.errors)

    return HttpResponseRedirect("/articles/%d#comment" % int(id))
示例#2
0
def blog_detail(request, pk):
    post = Post.objects.get(pk=pk)
    comments = Comment.objects.filter(post=post)

    form = CommentForm()
    if request.method == "POST":
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = Comment(
                author=form.cleaned_data["author"],
                body=form.cleaned_data["body"],
                post=post,
            )
            comment.save()

    context = {"post": post, "comments": comments, "form": form}
    return render(request, "blog_detail.html", context)
示例#3
0
文件: views.py 项目: Thoshh/yzu-opera
def save_comment(request):
    comment_author=request.POST.get("name",None)
    comment_email=request.POST.get("email",None)
    comment_website=request.POST.get("homepage",None)
    comment_body=request.POST.get("content",None)
    comment_post_id=request.POST.get("postid",None)
    if not comment_author or not len(comment_author):
        if comment_post_id:
            return HttpResponseRedirect("/blog/post/"+comment_post_id+"/")
        else:
            return HttpResponseRedirect("/blog/")
    try:
        onepost=Entry.objects.get(id=comment_post_id)
        comment=Comment(author=comment_author, email=comment_email, website=comment_website, body=comment_body, date=datetime.datetime.now(),post=onepost)
        comment.save()
        return HttpResponseRedirect("/blog/post/"+comment_post_id+"#cmt_form")
        #return HttpResponseRedirect("/blog/")
    except Exception,e:
        return HttpResponse("Write Error")
示例#4
0
def comment_add(request, id):
    article = get_object_or_404(Article, pk=id)
    #add comment
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            #comment_parent=Comment(id=cd["comment_parent_id"]),
            post = Comment(article=Article(id=id),
                           user=User(id=cd["user_id"]),
                           email=cd["email"],
                           author=cd["author"],
                           content=cd["content"])
            if cd["comment_parent_id"] != None:
                post.comment_parent = Comment(id=cd["comment_parent_id"])

            post.save()
            article.comment_count += 1
            article.save()

        print("%r" % form.errors)

    return HttpResponseRedirect("/articles/%d#comment" % int(id))