예제 #1
0
파일: urls.py 프로젝트: edwingoo/mywebapp
def api_get_post(post_id):
    post_data = Posts.get(post_id)
    if post_data:
        print post_data
        print 'api'
        return dict(name=post_data.post_name, excerpt=post_data.post_excerpt, content=post_data.post_content)
    raise APIResourceNotFoundError('post')
예제 #2
0
파일: urls.py 프로젝트: edwingoo/mywebapp
def api_delete_post(post_id):
    check_admin()
    post_data = Posts.get(post_id)
    if not post_data:
        raise APIResourceNotFoundError('blog')
    post_data.delete()
    return dict(post_id=post_id)
예제 #3
0
파일: urls.py 프로젝트: edwingoo/mywebapp
def manage_posts_edit(post_id):
    """
    博客编辑页
    :param post_id:
    :return:
    """
    post_data = Posts.get(post_id)
    if post_data is None:
        raise notfound()
    return dict(id=post_id, action='/api/posts/%s' % post_id, redirect='/manage/posts', user=ctx.request.user)
예제 #4
0
파일: urls.py 프로젝트: edwingoo/mywebapp
def post_view(post_id):
    post_data = Posts.get(post_id)
    if post_data is None:
        raise notfound()
    post_data.post_content = markdown.markdown(post_data.post_content, extensions=['markdown.extensions.nl2br', 'markdown.extensions.fenced_code', 'markdown.extensions.codehilite', 'markdown.extensions.toc'], extension_configs={'markdown.extensions.codehilite':{
        'linenums':True
    }})
    # logging.info(post_data.post_content)
    # print post_data.post_content
    return dict(post=post_data, user=ctx.request.user)
예제 #5
0
파일: urls.py 프로젝트: edwingoo/mywebapp
def api_update_post(post_id):
    """
    博客修改
    :param post_id:
    :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.')
    post_data = Posts.get(post_id)
    post_data.post_name = name
    post_data.post_excerpt = excerpt
    post_data.post_content = content
    post_data.post_modified = time.time()
    post_data.update()
    return post_data