def dispatch_request(self): if request.method == 'POST': file = request.files['myfile'] if file and '.' in file.filename and file.filename.split( '.')[1] == 'xlsx': filename = 'jiekou.xlsx' file.save(filename) jiekou_bianhao,project_nam,model_nam,interface_name,interface_url, interface_header,\ interface_meth, interface_par, interface_bas,interface_type = pasre_inter(filename) if len(interface_meth) > Config_daoru_xianzhi: flash(u'系统目前支持的导入有限制,请分开导入') return redirect(url_for('interface.daoru_inter')) try: for i in range(len(jiekou_bianhao)): projects_id = Project.query.filter_by( project_name=project_nam[i]).first() if projects_id is None: flash('找不到项目,请确定导入的项目是否存在') return redirect(url_for('interface.daoru_inter')) model_id = Model.query.filter_by( model_name=model_nam[i]).first() if model_id is None: flash('找不到模块不存在!,请确定导入的项目是否存在') return redirect(url_for('interface.daoru_inter')) new_interface = Interface( projects_id=projects_id.id, model_id=model_id.id, Interface_name=str(interface_name[i]), Interface_url=str(interface_url[i]), Interface_headers=str(interface_header[i]), Interface_meth=str(interface_meth[i]), Interface_par=(interface_par[i]), Interface_back=str(interface_bas[i]), Interface_user_id=User.query.filter_by( username=session.get('username')).first().id, interfacetype=interface_type[i]) db.session.add(new_interface) db.session.commit() flash(u'导入成功') return redirect(url_for('home.interface')) except Exception as e: print(e) flash(u'导入失败,请检查') return render_template('daoru.html') flash(u'导入失败') return render_template('daoru.html') return render_template('daoru.html')
def dispatch_request(self): if request.method == 'POST': file = request.files['myfile'] if file and '.' in file.filename and file.filename.split('.')[1]=='xlsx': filename='jiekoucase.xlsx' file.save(filename) jiekou_bianhao,interface_name,project_nam, model_nam, interface_url,interfac_header, interface_meth, interface_par, interface_bas = pasre_inter(filename) try: for i in range(len(jiekou_bianhao)): projects_id = Project.query.filter_by(project_name=project_nam[i]).first().id model_id = Model.query.filter_by(model_name=model_nam[i]).first().id new_interface = InterfaceTest(projects_id=projects_id, model_id=model_id,Interface_name=str(interface_name[i]), Interface_url=str(interface_url[i]),Interface_headers=interfac_header[i],Interface_meth=str(interface_meth[i]), Interface_pase=(interface_par[i]),Interface_assert=str(interface_bas[i]),Interface_user_id=User.query.filter_by(username=session.get('username')).first().id) db.session.add(new_interface) db.session.commit() flash(u'导入成功') return redirect(url_for('home.yongli')) except Exception as e: db.session.rollback() flash(u'导入失败,原因:%s'%e) return render_template('daoru_case.html') flash(u'导入失败') return render_template('daoru_case.html') return render_template('daoru_case.html')