def upload(): if 'file' not in request.files: flash('No file part') return redirect(request.url) f = request.files['file'] if f.filename == '': flash('No selected file') return redirect(request.url) if f: filename = secure_filename(f.filename) f.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) name = request.form['name'] exited = File.query.filter_by(name=name).first() if exited: # 更新文件 exited.path = filename db.session.commit() else: # 创建一条记录 file = File() file.name = name file.path = filename db.session.add(file) db.session.commit() return redirect(url_for('manage'))
def show(self): while True: window = self.window event, values = window.read() if event == "submit": file = File(None, values['name'], values['path'], self.doc.id) fn = self.make_file_on_disk(self.person, self.doc, file) if fn: file.path = fn self.service.add_file(file) break elif event == "reset": window.Element("name").Update(value= "") window.Element("doc").Update(value= "") else: break window.Close()