Exemplo n.º 1
0
def api_create_post():
    """
    博客创建
    :return:
    """
    check_admin()
    i = ctx.request.input(name='', excerpt='', content='')
    name = i.name.strip()
    excerpt = i.excerpt.strip()
    content = i.content.strip()
    if not name:
        raise APIValueError('name', 'name cannot be empty.')
    if not excerpt:
        raise APIValueError('excerpt', 'excerpt cannot be empty.')
    if not content:
        raise APIValueError('content', 'content cannot be empty.')
    user = ctx.request.user
    posts = Posts(post_name=name, post_excerpt=excerpt, post_content=content, post_author=user.user_name)
    print posts
    posts.insert()
    return posts