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
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
def api_create_blog(request, *, name, summary, content): #校验当前用户权限: check_admin(request) #校验传递值中参数‘name’是否为空或空串,为空则抛出异常: if not name or not name.strip(): #参数‘name’为空则抛出异常: raise APIValueError('name', 'name cannot be empty.') #校验传递值中参数‘summary’是否为空或空串,为空则抛出异常: if not summary or not summary.strip(): raise APIValueError('summary', 'summary cannot be empty.') #校验传递值中参数‘content’是否为空或空串,为空则抛出异常: if not content or not content.strip(): raise APIValueError('content', 'content cannot be empty.') #创建Blog实例: 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()) #将Blog信息存储到数据库: yield from blog.save() return blog