()
return jsonify({'data': end_data, 'total': total, 'status': 1, 'userData': user_data})
查找项目
查找项目
查找项目
def find_project():
    """ 查找项目 """
    data = request.json
    project_name = data.get('projectName')

    page = data.get('page') if data.get('page') else 1
    per_page = data.get('sizePage') if data.get('sizePage') else 10
    user_data = [{'user_id': u.id, 'user_name': u.name} for u in User.query.all()]
    if project_name:
        _data = Project.query.filter(Project.name.like('%{}%'.format(project_name)))
        if not _data:
            return jsonify({'msg': '没有该项目', 'status': 0})
    else:
        _data = Project.query.order_by(Project.id.asc())
    pagination = _data.paginate(page, per_page=per_page, error_out=False)
    items = pagination.items
    total = pagination.total
    end_data = [{'id': c.id,
                 'host': c.host,
                 'name': c.name,
                 'choice': c.environment_choice,
                 'principal': User.query.filter_by(id=c.user_id).first().name,
                 'host_two': c.host_two, 'host_three': c.host_three, 'host_four': c.host_four} for c in items]
    return jsonify({'data': end_data, 'total': total, 'status': 1, 'userData': user_data})
def find_project ( ) : data = request . json project_name = data . get ( 'projectName' ) page = data . get ( 'page' ) if data . get ( 'page' ) else 1 per_page = data . get ( 'sizePage' ) if data . get ( 'sizePage' ) else 10 user_data = [ { 'user_id' : u . id , 'user_name' : u . name } for u in User . query . all ( ) ] if project_name : _data = Project . query . filter ( Project . name . like ( '%{}%' . format ( project_name ) ) ) if not _data : return jsonify ( { 'msg' : '没有该项目', 'status' : 0}) else : _data = Project . query . order_by ( Project . id . asc ( ) ) pagination = _data . paginate ( page , per_page = per_page , error_out = False ) items = pagination . items total = pagination . total end_data = [ { 'id' : c . id , 'host' : c . host , 'name' : c . name , 'choice' : c . environment_choice , 'principal' : User . query . filter_by ( id = c . user_id ) . first ( ) . name , 'host_two' : c . host_two , 'host_three' : c . host_three , 'host_four' : c . host_four } for c in items ] return jsonify ( { 'data' : end_data , 'total' : total , 'status' : 1 , 'userData' : user_data } )