コード例 #1
0
def index(request):
    summary = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, ' \
              'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
    blogs = [
        Blog(id='1',
             name='Test Blog',
             summary=summary,
             created_at=time.time() - 120),
        Blog(id='2',
             name='Something New',
             summary=summary,
             created_at=time.time() - 3600),
        Blog(id='3',
             name='Learn Swift',
             summary=summary,
             created_at=time.time() - 7200),
    ]
    return {'__template__': 'blogs.html', 'blogs': blogs}
コード例 #2
0
ファイル: routes.py プロジェクト: sjl421/Python3Learning
async def api_create_blog(request, *, name, summary, content):
    helper.check_user(
        request.__user__)  # request.__user__是从拦截器auth_factory中绑定后传递到此handler
    helper.check_string(name=name, summary=summary, content=content)
    blog = Blog(user_id=request.__user__.id,
                user_name=request.__user__.name,
                user_image=request.__user__.image,
                name=name.strip(),
                summary=summary.strip(),
                content=content.strip())
    await blog.save()
    return blog
コード例 #3
0
def api_create_blog(request, *, name, summary, content):
    check_admin(request)
    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 = Blog(user_id=request.__user__.id,
                user_name=request.__user__.name,
                user_image=request.__user__.image,
                name=name.strip(),
                summary=summary.strip(),
                content=content.strip())
    yield from blog.save()
    return blog