コード例 #1
0
ファイル: views.py プロジェクト: laiqun/Small-CMS
def floorcomm(request):  # 盖楼评论
    logger.debug(request.POST["content_id"])  # 应该修改为分页形式的
    logger.debug(request.POST["comment"])  # 应该修改为分页形式的
    logger.debug(request.POST["comment_id"])  # 应该修改为分页形式的

    # if request.method == 'POST':
    # logger.debug(request)  # 应该修改为分页形式的
    # data = {'flag': 'true'}
    # return HttpResponse(json.dumps(data), content_type='application/json')
    commentnew = Comment(
        blog_id=BlogPost.objects.get(id=int(request.POST["content_id"])),
        user_id=request.user.person,
        body=request.POST["comment"],
        parent_id=Comment.objects.get(id=int(request.POST["comment_id"])),
    )
    commentnew.save()
    data = {"flag": "true", "list": "", "msg": "回复成功!"}
    return HttpResponse(json.dumps(data), content_type="application/json")
コード例 #2
0
ファイル: views.py プロジェクト: laiqun/Small-CMS
def blog_detail(request, id):
    if request.method == "POST":
        logger.debug(request.POST)
        try:
            commentnew = Comment(
                blog_id=BlogPost.objects.get(id=int(request.POST["blogid"])),
                user_id=request.user.person,
                body=request.POST["content"],
            )
            commentnew.save()
        except AttributeError:
            return HttpResponseRedirect("/login")
        return HttpResponseRedirect("/")
    else:
        post = BlogPost.objects.get(id=id)
        comments = Comment.objects.all().filter(blog_id=id, parent_id__isnull=True).order_by("-timestamp")
        try:
            postsall_collect = request.user.person.blogpost_set.all()
            if post in postsall_collect:
                post.collect = True
            return render_to_response("detail.html", {"post": post, "comments": comments})
        except AttributeError:
            return render_to_response("detail.html", {"post": post, "comments": comments})