コード例 #1
0
def api_delete_comments(request, *, id):
    check_admin(request)
    c = yield from Comment.find(id)
    if c is None:
        raise APIResourceNotFoundError('Comment')
    yield from c.remove()
    return dict(id=id)
コード例 #2
0
ファイル: handlers.py プロジェクト: mingjian97/pythonDemo
async def api_delete_comments(id,request):
    check_admin(request)
    c=await Comment.find(id)
    if c is None:
        raise APIResourceNotFoundError('Comment')
    await c.remove()
    return dict(id=id)
コード例 #3
0
async def api_delete_comments(id, request):
    logging.info('york----------------------管理员删除评论API')
    check_admin(request)
    c = await Comment.find(id)
    if c is None:
        raise APIResourceNotFoundError('Comment')
    await c.remove()
    return dict(id=id)
コード例 #4
0
ファイル: handlers.py プロジェクト: zuocaijian/HiPythonWeb
async def api_delete_comment(id, request):
    '''
    后端API:删除评论
    '''
    check_admin(request)
    comment = await Comment.find(id)
    if comment is None:
        raise APIResourceNotFoundError('Comment')
    await comment.remove()
    return dict(id=id)
コード例 #5
0
def api_delete_comments(id, request):
    #校验当前用户权限:
    check_admin(request)
    #数据库Comment表中查询指定评论信息:
    c = yield from Comment.find(id)
    #查询无结果则抛出异常:
    if c is None:
        raise APIResourceNotFoundError('Comment')
    #将Comment信息从数据库删除:
    yield from c.remove()
    return dict(id=id)
コード例 #6
0
ファイル: handlers.py プロジェクト: mingjian97/pythonDemo
async def api_create_comment(id,request,*,content):
    user=request.__user__
    if user is None:
        raise APIPermissionError('please signin first')
    if not content or not content.strip():
        raise APIValueError('content')
    blog=await Blog.find(id)
    if blog is None:
        raise APIResourceNotFoundError('Blog')
    comment=Comment(blog_id=blog.id,user_id=user.id,user_name=user.name,user_image=user.image,content=content.strip())
    await comment.save()
    return comment
コード例 #7
0
ファイル: handlers.py プロジェクト: shiqichang/poetry
async def api_create_comment(request, *, id, content):
    user = request.__user__
    if user is None:
        raise APIPermissionError('Please login first')
    if not content or not content.strip():
        raise APIValueError('comment', 'comment cannot be empty')
    quote = await Quote.find(id)
    if quote is None:
        raise APIResourceNotFoundError('Quote')
    comment = Comment(quote_id=quote.id,
                      user_id=user.id,
                      user_name=user.name,
                      user_image=user.image,
                      content=content.strip())
    await comment.save()
    return comment
コード例 #8
0
async def api_create_comment(blog_id, request, *, content):
    check_admin(request)
    user = request.__user__
    if user is None:
        raise APIPermissionError()
    if not content or not content.strip():
        raise APIValueError('content')
    blog = Blog.find(blog_id)
    if blog is None:
        raise APIResourceNotFoundError('Blog')
    comment = Comment(blog_id=blog_id,
                      user_id=request.__user__.id,
                      user_name=request.__user__.name,
                      user_image=request.__user__.image,
                      content=content)
    await comment.save()
    return comment
コード例 #9
0
async def api_delete_users(id, request):
    check_admin(request)
    id_buff = id
    user = await User.find(id)
    if user is None:
        raise APIResourceNotFoundError('Comment')
    await user.remove()
    # 给被删除的用户在评论中标记
    comments = await Comment.findAll('user_id=?',[id])
    if comments:
        for comment in comments:
            id = comment.id
            c = await Comment.find(id)
            c.user_name = c.user_name + ' (该用户已被删除)'
            await c.update()
    id = id_buff
    return dict(id=id)
コード例 #10
0
def api_create_comment(id, request, *, content):
    #获取请求中的用户信息:
    user = request.__user__
    #用户信息为None则抛出异常:
    if user is None:
        raise APIPermissionError('Please signin first.')
    #参数中内容信息为空,抛出异常:
    if not content or not content.strip():
        raise APIValueError('content')
    #数据库Blog表中查询指定文章信息:
    blog = yield from Blog.find(id)
    #查询无结果则抛出异常:
    if blog is None:
        raise APIResourceNotFoundError('Blog')
    #创建comment实例:
    comment = Comment(blog_id=blog.id, user_id=user.id, user_name=user.name, user_image=user.image, content=content.strip())
    #将Comment信息存储到数据库:
    yield from comment.save()
    return comment