def upload_file(): form = UploadForm() info_requester = InfoRequestHandler(current_user.id) file_info = info_requester.get_file_details() if form.validate_on_submit(): filename = secure_filename(form.file.data.filename) data = form.file.data.read() file_id = info_requester.add_new_file([filename, data]) info_requester.set_recent_file_details([file_id]) return redirect(url_for('index')) return render_template('upload_file.html', title='Upload file with budget data', form=form, file_info=file_info)
def file_admin(): form = FileAdminForm() info_requester = InfoRequestHandler(current_user.id) file_info = info_requester.get_file_details() if not file_info: return redirect(url_for('upload_file')) # someday need to abstract this form.files.choices = [(f.id, f.filename + "; " + str(f.uploaded_timestamp)) for f in info_requester.get_source_list()] if request.method == 'POST': if form.select.data: info_requester.set_recent_file_details([int(form.files.data)]) elif form.delete.data: info_requester.delete_source([int(form.files.data)]) elif form.delete_all.data: info_requester.delete_all_sources() return redirect(url_for('upload_file')) return redirect(url_for('index')) return render_template('file_admin.html', title='files...', form=form, file_info=file_info)