def members(self, group_id=None, project_id=None, page=0, size=10, kw=None): """ 获取单条记录 :param role_id: :return: """ group_id = group_id if group_id else self.group_id project_id = project_id if project_id else self.project_id source_id = group_id if group_id else project_id source_type = self.source_type_group if group_id else self.source_type_project query = UserModel.query \ .filter(UserModel.status.notin_([self.status_remove])) \ .filter(MemberModel.source_id == source_id) \ .filter(MemberModel.source_type == source_type) query = query.join(MemberModel, UserModel.id == MemberModel.user_id) if kw: query = query.filter(or_(UserModel.username.like('%' + kw + '%'), UserModel.email.like('%' + kw + '%'))) query = query.add_columns(MemberModel.access_level, UserModel.id) count = query.count() data = query.order_by(MemberModel.id.asc()).offset(int(size) * int(page)).limit(size).all() current_app.logger.info(data) list = [] user_ids = [] for p in data: item = p[0].to_json() item['role'] = p[1] user_ids.append(p[2]) list.append(item) current_app.logger.info(list) return list, count, user_ids
def members(self, group_id=None, project_id=None, page=0, size=10, kw=None): """ 获取单条记录 :param role_id: :return: """ group_id = group_id if group_id else self.group_id project_id = project_id if project_id else self.project_id source_id = group_id if group_id else project_id source_type = self.source_type_group if group_id else self.source_type_project query = UserModel.query \ .filter(UserModel.status.notin_([self.status_remove])) \ .filter(MemberModel.source_id == source_id) \ .filter(MemberModel.source_type == source_type) query = query.join(MemberModel, UserModel.id == MemberModel.user_id) if kw: query = query.filter(or_(UserModel.username.like('%' + kw + '%'), UserModel.email.like('%' + kw + '%'))) query = query.add_columns(MemberModel.access_level, UserModel.id) count = query.count() data = query.order_by(MemberModel.id.asc()).offset(int(size) * int(page)).limit(size).all() current_app.logger.info(data) list = [] user_ids = [] for p in data: item = p[0].to_json() item['role'] = p[1] user_ids.append(p[2]) list.append(item) current_app.logger.info(list) return list, count, user_ids
def list(self, page=0, size=10, kw=None, space_id=None): """ 获取分页列表 :param page: :param size: :param kw: :return: """ SpaceModel = model.space.SpaceModel query = self.query.filter( EnvironmentModel.status.notin_([self.status_remove])) if kw: query = query.filter( or_(EnvironmentModel.name.like('%' + kw + '%'), SpaceModel.name.like('%' + kw + '%'))) if space_id: query = query.filter(EnvironmentModel.space_id == space_id) query = query.join(SpaceModel, SpaceModel.id == EnvironmentModel.space_id) query = query.add_columns(SpaceModel.name) count = query.count() data = query.order_by(EnvironmentModel.id.desc()).offset( int(size) * int(page)).limit(size).all() env_list = [] for p in data: item = p[0].to_json() item['space_name'] = p[1] env_list.append(item) return env_list, count
def list(self, page=0, size=10, kw=None, space_id=None): """ 获取分页列表 :param page: :param size: :param kw: :return: """ SpaceModel = model.space.SpaceModel query = self.query.filter(EnvironmentModel.status.notin_([self.status_remove])) if kw: query = query.filter(or_(EnvironmentModel.name.like('%' + kw + '%'), SpaceModel.name.like('%' + kw + '%'))) if space_id: query = query.filter(EnvironmentModel.space_id == space_id) query = query.join(SpaceModel, SpaceModel.id == EnvironmentModel.space_id) query = query.add_columns(SpaceModel.name) count = query.count() data = query.order_by(EnvironmentModel.id.desc()).offset(int(size) * int(page)).limit(size).all() env_list = [] for p in data: item = p[0].to_json() item['space_name'] = p[1] env_list.append(item) return env_list, count