()
添加配置
添加配置
添加配置
def add_scene_config():
    """ 添加配置 """
    data = request.json
    project_id = data.get('projectId')
    name = data.get('sceneConfigName')
    ids = data.get('id')
    func_address = json.dumps(data.get('funcAddress'))
    variable = data.get('variable')
    if not project_id:
        return jsonify({'msg': '请选择项目', 'status': 0})
    if re.search('\${(.*?)}', variable, flags=0) and not func_address:
        return jsonify({'msg': '参数引用函数后，必须引用函数文件', 'status': 0})

    num = auto_num(data.get('num'), Config, project_id=project_id)

    if ids:
        old_data = Config.query.filter_by(id=ids).first()
        old_num = old_data.num
        list_data = Config.query.filter_by(project_id=project_id).all()

        if Config.query.filter_by(name=name, project_id=project_id).first() and name != old_data.name:
            return jsonify({'msg': '配置名字重复', 'status': 0})

        num_sort(num, old_num, list_data, old_data)
        old_data.name = name
        old_data.func_address = func_address
        old_data.project_id = project_id
        old_data.variables = variable
        db.session.commit()
        return jsonify({'msg': '修改成功', 'status': 1})
    else:
        if Config.query.filter_by(name=name, project_id=project_id).first():
            return jsonify({'msg': '配置名字重复', 'status': 0})

        else:
            new_config = Config(name=name, variables=variable, project_id=project_id, num=num,
                                func_address=func_address)
            db.session.add(new_config)
            db.session.commit()
            return jsonify({'msg': '新建成功', 'status': 1})
def add_scene_config ( ) : data = request . json project_id = data . get ( 'projectId' ) name = data . get ( 'sceneConfigName' ) ids = data . get ( 'id' ) func_address = json . dumps ( data . get ( 'funcAddress' ) ) variable = data . get ( 'variable' ) if not project_id : return jsonify ( { 'msg' : '请选择项目', 'status' : 0}) if re . search ( '\${(.*?)}' , variable , flags = 0 ) and not func_address : return jsonify ( { 'msg' : '参数引用函数后，必须引用函数文件', 'status': 0}) num = auto_num ( data . get ( 'num' ) , Config , project_id = project_id ) if ids : old_data = Config . query . filter_by ( id = ids ) . first ( ) old_num = old_data . num list_data = Config . query . filter_by ( project_id = project_id ) . all ( ) if Config . query . filter_by ( name = name , project_id = project_id ) . first ( ) and name != old_data . name : return jsonify ( { 'msg' : '配置名字重复', 'status':  0 ) num_sort ( num , old_num , list_data , old_data ) old_data . name = name old_data . func_address = func_address old_data . project_id = project_id old_data . variables = variable db . session . commit ( ) return jsonify ( { 'msg' : '修改成功', 'statu s : 1}) else : if Config . query . filter_by ( name = name , project_id = project_id ) . first ( ) : return jsonify ( { 'msg' : '配置名字重复', 'status':  0 ) else : new_config = Config ( name = name , variables = variable , project_id = project_id , num = num , func_address = func_address ) db . session . add ( new_config ) db . session . commit ( ) return jsonify ( { 'msg' : '新建成功', 'statu s : 1})