コード例 #1
0
ファイル: views.py プロジェクト: Sola-Lufkin/iDentalk-WEB2
def comment_save(request):
    """
    This function comment_save will save user's comments for this post.
    @version 0.5
    """

    result = {}

    user = request.user
    print(request.user.username)
    UserObj = User.objects.get(username=user)

    print request.POST
    pid = request.POST['pid']
    comment = request.POST['comment']
    comment = comment.strip()

    if len(comment) > 600:
        result = {
                "status": False,
                "msg": "At most enter 600 characters."
        }

        return JsonResponse(result)

    else:
        ip = request.META['REMOTE_ADDR']

        PostObj = Post.objects.get(id = pid)
        comment_count_bef = PostObj.comment_count
        comment_count = comment_count_bef + 1

        Post.objects.filter(id = pid).update(comment_count=comment_count)
        print "Post Update Success!"
        PostObj_new = Post.objects.get(id = pid)

        CommentInsert = Comment(comment_content=comment, comment_author_ip=ip,
                                user_id=user, post_id=PostObj_new)
        CommentInsert.save(force_insert=True)

        CommentObj = Comment.objects.get(id=CommentInsert.id)
        print(str(CommentObj.comment_date))
        print(CommentObj.comment_date)
        print "Comment Insert Success!"
        comment_identity = Base.objects.get(user=CommentObj.user_id).identity

        result = {
                "status": True,
                "id": CommentObj.id,
                "content": CommentObj.comment_content,
                "date": str(CommentObj.comment_date),
                "humandate": humantime(CommentObj.comment_date),
                "username": user.last_name,
                "comment_count": PostObj_new.comment_count,
                "comment_identity": comment_identity
        }

        return JsonResponse(result)
コード例 #2
0
ファイル: views.py プロジェクト: mrigdon/Apartme-Django
def create_comment(request):
    if request.POST:
        # get POST data
        body = request.POST['body']
        post_id = request.POST['post_id']
        post = Post.objects.get(id=post_id)
        author = request.user

        # create new Comment
        comment = Comment(body=body, post=post, author=author)
        comment.save()

        return HttpResponseRedirect('/stream/')
コード例 #3
0
ファイル: views.py プロジェクト: mrigdon/Apartme-Django
def delete_comment(request, id):
    comment = Comment.objects.get(id=id)
    Comment.delete(comment)

    return HttpResponseRedirect('/stream/')