def api_create_project(request, *, project_id,project_name,project_level): # 只有管理员可以写博客 #check_admin(request) #不能为空 if not project_id or not project_id.strip(): raise APIValueError('name', 'name cannot be empty') if not project_name or not project_name.strip(): raise APIValueError('summary', 'summary cannot be empty') # 根据传入的信息,构建一条项目数据 project = Project( project_id=project_id, project_name=project_name, #project_status=project_status, #project_stage=project_stage, #project_docFlag=project_docFlag, project_level=project_level, project_manager=request.__user__.user_name # project_department=project_department, # project_resource=project_resource, # project_environment=project_environment ) p_r = yield from Project.findAll(where='project_id=?', args=[project_id]) # 查询id是否已注册,查看ORM框架源码 if len(p_r) > 0: raise APIError('新建项目失败', 'project_id', 'project_id is already in use.') # 保存 yield from project.save() return project
def api_projects(*, page='1'): page_index = get_page_index(page) num = yield from Project.findNumber('count(id)') p = Page(num, page_index) if num == 0: return dict(page=p, projects=()) projects = yield from Project.findAll(orderBy='created_at desc', limit=(p.offset, p.limit)) return dict(page=p, projects=projects)
def api_show_projects(*,request, page='1'): # 获取项目信息 page_index = get_page_index(page) num = yield from Project.findNumber('count(project_id)') p = Page(num, page_index, 5) if num == 0: return dict(page=p, projects=()) projects = yield from Project.findAll('project_manager= ?',[request.__user__.user_name],orderBy='created_at asc', limit=(p.offset, p.limit)) return dict(page=p, projects=projects)