()
return jsonify(
        {'data': _d, 'user_pros': user_pros, })
获取基本信息
获取基本信息
获取基本信息
def get_pro_gather():
    """ 获取基本信息 """
    # data = request.query_string
    # print(dir(request))
    # print(data)
    # if current_user.id == 4:
    # _pros = P"""
    #     select project.id, config.id as config_id, config.name as config_name from project
    #     left join config
    #     on project.id = config.project_id
    #     """roject.query.order_by(case((Project.user_id == current_user.id, 1))).all()
    _d = []
    sql = """
        SELECT * FROM `project`
        ORDER BY CASE when user_id={} then 0 end DESC, id DESC
        """.format(current_user.id)
    project_data = list(db.session.execute(sql))
    sql = """
    select project.id, config.id as config_id, config.name as config_name from project 
    left join config
    on project.id = config.project_id
    """
    config_d = list(db.session.execute(sql))

    sql = """
        select project.id, module.id as module_id, module.name as module_name from project 
        left join module
        on project.id = module.project_id
        """
    module_d = list(db.session.execute(sql))

    sql = """
        select project.id, case_set.id as case_set_id, case_set.name as case_set_name from project 
        left join case_set
        on project.id = case_set.project_id
        """
    case_set_d = list(db.session.execute(sql))
    user_pros = False

    for p in project_data:
        if p[0] == current_user.id:
            user_pros = True
        # print(p.id)
        # 获取每个项目下的url
        if p[6] == 'first':
            url = json.loads(p[2])
        elif p[6] == 'second':
            url = json.loads(p[3])
        elif p[6] == 'third':
            url = json.loads(p[4])
        else:
            url = json.loads(p[5])

        _d.append({'name': p.name,
                   'id': p.id,
                   'url': url,
                   'config_data': [{'id': d[1], 'name': d[2]} for d in config_d if d[0] == p[0] and d[1]],
                   'module_data': [{'id': d[1], 'name': d[2]} for d in module_d if d[0] == p[0] and d[1]],
                   'set_data': [{'id': d[1], 'name': d[2]} for d in case_set_d if d[0] == p[0] and d[1]], })
    # s = time.time()
    #
    # my_pros = Project.query.filter_by(user_id=current_user.id).first()
    # e1 = time.time()
    # print(e1-s)

    # for p in _pros:
    #     # pro_and_id[p.name] = p.id
    #
    #     pro_and_id.append({'name': p.name, 'id': p.id})
    #
    #     if b'case' in request.query_string:
    #         # 获取每个项目下的配置信息
    #         scene_config_lists[p.id] = [{'name': c.name, 'configId': c.id} for c in p.configs]
    #
    #         # 获取每个项目下的接口模块
    #         pro[p.id] = [{'name': m.name, 'moduleId': m.id} for m in p.modules]
    #     #
    #     if b'task' in request.query_string:
    #         # 获取每个项目下的用例集
    #         set_list[p.id] = [{'label': s.name, 'id': s.id} for s in p.case_sets]
    #
    #         # 获取每个用例集的用例
    #         for s in p.case_sets:
    #             scene_list["{}".format(s.id)] = [{'label': case.name, 'id': case.id} for case in
    #                                              s.cases]
    #             # scene_list["{}".format(s.id)] = [{'label': scene.name, 'id': scene.id} for scene in
    #             #                                  Case.get_all(case_set_id=s.id)]
    #
    #     # 获取每个项目下的url
    #     if p.environment_choice == 'first':
    #         pro_url[p.id] = json.loads(p.host)
    #     elif p.environment_choice == 'second':
    #         pro_url[p.id] = json.loads(p.host_two)
    #     elif p.environment_choice == 'third':
    #         pro_url[p.id] = json.loads(p.host_three)
    #     elif p.environment_choice == 'fourth':
    #         pro_url[p.id] = json.loads(p.host_four)
    #
    # if my_pros:
    #     # my_pros = {'pro_name': my_pros.name, 'pro_id': my_pros.id, 'model_list': pro[my_pros.name]}
    #     user_pros = True
    # return jsonify(
    #     {'data': True, 'user_pros': True, })
    return jsonify(
        {'data': _d, 'user_pros': user_pros, })
def get_pro_gather ( ) : # data = request.query_string # print(dir(request)) # print(data) # if current_user.id == 4: # _pros = P""" #     select project.id, config.id as config_id, config.name as config_name from project #     left join config #     on project.id = config.project_id #     """roject.query.order_by(case((Project.user_id == current_user.id, 1))).all() _d = [ ] sql = """
        SELECT * FROM `project`
        ORDER BY CASE when user_id={} then 0 end DESC, id DESC
        """ . format ( current_user . id ) project_data = list ( db . session . execute ( sql ) ) sql = """
    select project.id, config.id as config_id, config.name as config_name from project 
    left join config
    on project.id = config.project_id
    """ config_d = list ( db . session . execute ( sql ) ) sql = """
        select project.id, module.id as module_id, module.name as module_name from project 
        left join module
        on project.id = module.project_id
        """ module_d = list ( db . session . execute ( sql ) ) sql = """
        select project.id, case_set.id as case_set_id, case_set.name as case_set_name from project 
        left join case_set
        on project.id = case_set.project_id
        """ case_set_d = list ( db . session . execute ( sql ) ) user_pros = False for p in project_data : if p [ 0 ] == current_user . id : user_pros = True # print(p.id) # 获取每个项目下的url if p [ 6 ] == 'first' : url = json . loads ( p [ 2 ] ) elif p [ 6 ] == 'second' : url = json . loads ( p [ 3 ] ) elif p [ 6 ] == 'third' : url = json . loads ( p [ 4 ] ) else : url = json . loads ( p [ 5 ] ) _d . append ( { 'name' : p . name , 'id' : p . id , 'url' : url , 'config_data' : [ { 'id' : d [ 1 ] , 'name' : d [ 2 ] } for d in config_d if d [ 0 ] == p [ 0 ] and d [ 1 ] ] , 'module_data' : [ { 'id' : d [ 1 ] , 'name' : d [ 2 ] } for d in module_d if d [ 0 ] == p [ 0 ] and d [ 1 ] ] , 'set_data' : [ { 'id' : d [ 1 ] , 'name' : d [ 2 ] } for d in case_set_d if d [ 0 ] == p [ 0 ] and d [ 1 ] ] , } ) # s = time.time() # # my_pros = Project.query.filter_by(user_id=current_user.id).first() # e1 = time.time() # print(e1-s) # for p in _pros: #     # pro_and_id[p.name] = p.id # #     pro_and_id.append({'name': p.name, 'id': p.id}) # #     if b'case' in request.query_string: #         # 获取每个项目下的配置信息 #         scene_config_lists[p.id] = [{'name': c.name, 'configId': c.id} for c in p.configs] # #         # 获取每个项目下的接口模块 #         pro[p.id] = [{'name': m.name, 'moduleId': m.id} for m in p.modules] #     # #     if b'task' in request.query_string: #         # 获取每个项目下的用例集 #         set_list[p.id] = [{'label': s.name, 'id': s.id} for s in p.case_sets] # #         # 获取每个用例集的用例 #         for s in p.case_sets: #             scene_list["{}".format(s.id)] = [{'label': case.name, 'id': case.id} for case in #                                              s.cases] #             # scene_list["{}".format(s.id)] = [{'label': scene.name, 'id': scene.id} for scene in #             #                                  Case.get_all(case_set_id=s.id)] # #     # 获取每个项目下的url #     if p.environment_choice == 'first': #         pro_url[p.id] = json.loads(p.host) #     elif p.environment_choice == 'second': #         pro_url[p.id] = json.loads(p.host_two) #     elif p.environment_choice == 'third': #         pro_url[p.id] = json.loads(p.host_three) #     elif p.environment_choice == 'fourth': #         pro_url[p.id] = json.loads(p.host_four) # # if my_pros: #     # my_pros = {'pro_name': my_pros.name, 'pro_id': my_pros.id, 'model_list': pro[my_pros.name]} #     user_pros = True # return jsonify( #     {'data': True, 'user_pros': True, }) return jsonify ( { 'data' : _d , 'user_pros' : user_pros , } )