python类find()的实例源码

handlers.py 文件源码 项目:awesome-webapp 作者: TsangTen 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def get_blog(id):
    blog = await Blog.find(id)
    comments = await Comment.findAll('blog_id=?', [id], orderBy='created_at desc')
    for c in comments:
        c.html_content = text2html(c.content)
    blog.html_content = markdown2.markdown(blog.content)
    return {
        '__template__': 'blog.html',
        'blog': blog,
        'comments': comments
    }
handlers.py 文件源码 项目:awesome-webapp 作者: TsangTen 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def api_update_blog(id, request, *, name, summary, content):
    check_admin(request)
    blog = await Blog.find(id)
    if not name or not name.strip():
        raise APIValueError('name', 'name cannot be empty.')
    if not summary or not summary.strip():
        raise APIValueError('summary', 'summary cannot be empty.')
    if not content or not content.strip():
        raise APIValueError('content', 'content cannot be empty.')
    blog.name = name.strip()
    blog.summary = summary.strip()
    blog.content = content.strip()
    await blog.update()
    return blog
handlers.py 文件源码 项目:awesome-webapp 作者: TsangTen 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def api_delete_blog(request, *, id):
    check_admin(request)
    blog = await Blog.find(id)
    await blog.remove()
    return dict(id=id)
handlers.py 文件源码 项目:awesome-webapp 作者: TsangTen 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def api_get_blog(*, id):
    blog = await Blog.find(id)
    return blog
handlers.py 文件源码 项目:awesome-webapp 作者: TsangTen 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def api_delete_comments(id, request):
    check_admin(request)
    c = await Comment.find(id)
    if c is None:
        raise APIResourceNotFoundError('Comment', 'Not Found!')
    await c.remove()
    return dict(id=id)
handlers.py 文件源码 项目:python3-webapp 作者: chenpengcong 项目源码 文件源码 阅读 48 收藏 0 点赞 0 评论 0
def get_blog(id):
    '''
    ??blog???blog??.
    '''
    blog = await Blog.find(id)
    comments = await Comment.findAll('blog_id=?', [id], orderby='created_at desc')
    for c in comments:
        c.html_content = text2html(c.content)
    blog.html_content = markdown2.markdown(blog.content)
    return {
        '__template__' : 'blog.html',
        'blog' : blog,
        'comments' : comments
    }
handlers.py 文件源码 项目:python3-webapp 作者: chenpengcong 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def api_create_comment(id, request, *, content):
    '''
    ????, ????blog.html.
    '''
    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
handlers.py 文件源码 项目:python3-webapp 作者: chenpengcong 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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)
handlers.py 文件源码 项目:python3-webapp 作者: chenpengcong 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def api_get_blog(*, id):
    '''
    ????????, ????manage_blog_edit.html.
    '''
    blog = await Blog.find(id)
    return blog
handlers.py 文件源码 项目:python3-webapp 作者: chenpengcong 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def api_delete_blog(request, *, id):
    '''
    ????????.
    '''
    check_admin(request)
    blog = await Blog.find(id)
    await blog.remove()
    return dict(id = id)
handlers.py 文件源码 项目:python1 作者: lilizhiwei 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def cookie2user(cookie_str):
    '''
    Parse cookie and load user if cookie is valid.??cookie???????cookie???????
    '''
    if not cookie_str:
        return None
    try:
        # ?????????????????“-”??cookie?????id?????????????
        L = cookie_str.split('-') # ????str?list
        if len(L) != 3: # cookie????????????????????????????
            return None
        uid, expires, sha1 = L
        if int(expires) < time.time(): # ??????????cookie???
            return None
        user = yield from User.find(uid)  # ???????????
        if user is None:  # ??????????????
            return None
        # ??sha1?????????cookie??sha1?????
        s = '%s-%s-%s-%s' % (uid, user.passwd, expires, _COOKIE_KEY)
        # ????????????
        if sha1 != hashlib.sha1(s.encode('utf-8')).hexdigest():
            logging.info('invalid sha1')
            return None
        user.passwd = '******'
        # ??cookie??????????????????????????????
        # ?? ????????
        return user
    except Exception as e:
        logging.exception(e)
        return None

# ----------------------------------?????--------------------------------

# day14???
# ?????
handlers.py 文件源码 项目:python1 作者: lilizhiwei 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def api_get_blog(*, id):
    blog = yield from Blog.find(id)
    return blog

# day11??
# API?????????
handlers.py 文件源码 项目:python1 作者: lilizhiwei 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def api_delete_comments(id, request):
    check_admin(request)  #???????????
    c = yield from Comment.find(id)  # ?????????
    if c is None:
        raise APIResourceNotFoundError('Comment')
    yield from c.remove()  # ????
    return dict(id=id)  # ????????id

# day14??
# API:????
handlers.py 文件源码 项目:python1 作者: lilizhiwei 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def api_delete_blog(request, *, id):
    check_admin(request)
    blog = yield from Blog.find(id)
    yield from blog.remove()
    return dict(id=id)


问题


面经


文章

微信
公众号

扫码关注公众号