def post_csv(): # request.file <class 'werkzeug.datastructures.FileStorage'> # request.url is http://127.0.0.1:5000/ # check if the post request has the file part if 'file' not in request.files: log = 'no file field in request.' return render_template('fail.html', log=log) # print(request.files['file']) file = request.files['file'] # if user does not select file, browser also # submit an empty part without filename if file.filename == '': log = 'Empty filename.' return render_template('fail.html', log=log) if file and util.allowed_file(file.filename): # get filename in a safe way filename = secure_filename(file.filename) # check if the data folder exists, if not create one if os.path.exists(app.config['UPLOAD_FOLDER']) == False: os.makedirs(app.config['UPLOAD_FOLDER']) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) column_names, data_part = util.preview_csv( app.config['UPLOAD_FOLDER'] + filename) app.config['COL_NAMES'] = column_names return render_template('success.html', column_names=column_names, data_part=data_part)
def upload(): if request.method == 'POST': # request.file <class 'werkzeug.datastructures.FileStorage'> # request.url is http://127.0.0.1:5000/ # check if the post request has the file part if 'file' not in request.files: log = 'no file field in request.' return render_template('fail.html', log=log) # print(request.files['file']) file = request.files['file'] # if user does not select file, browser also # submit an empty part without filename if file.filename == '': # This part should use flash to output information log = 'Empty filename.' return render_template('fail.html', log=log) if file and util.allowed_file(file.filename): # get filename in a safe way filename = secure_filename(file.filename) app.config['_FILE'] = UPLOAD_FOLDER + filename app.config['filename'] = filename print(filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) column_names, data_part = util.preview_csv( app.config['UPLOAD_FOLDER'] + filename, 3) return render_template('upload2.html', column_names=column_names, data_part=data_part, filename=app.config['filename']) elif request.method == 'GET': app.config['_DATA_COLS'] = "" app.config['_DATE_COL'] = "" return render_template('upload.html')
def configure(): print(request.form) if 'filename' not in session: log = 'no file field in request.' return render_template('fail.html', log=log) else: filename = secure_filename(session.get('filename', None)) column_names, data_part = util.preview_csv( app.config['UPLOAD_FOLDER'] + filename) return render_template('configure.html', selected_columns=column_names)
def verify(): # print(session.get('filename', None)) if 'filename' not in session: log = 'no file field in request.' return render_template('fail.html', log=log) else: filename = secure_filename(session.get('filename', None)) column_names, data_part = util.preview_csv( app.config['UPLOAD_FOLDER'] + filename) return render_template('verify.html', column_names=column_names, data_part=data_part)
def verify(): column_names, data_part = util.preview_csv(app.config['_FILE'], 100) return render_template('verify.html', column_names=column_names, data_part=data_part, filename=app.config['filename'])
def upload2(): column_names, data_part = util.preview_csv(app.config['_FILE'], 3) return render_template('upload2.html', column_names=column_names, data_part=data_part, filename=app.config['filename'])
def dropPreviewColumnNames(): column_names, data_part = util.preview_csv( app.config['UPLOAD_FOLDER'] + 'NRDC_data.csv', 2) return render_template('UploadColumns.html', column_names=column_names)
def drop_Preview(rows): column_names, data_part = util.preview_csv( app.config['UPLOAD_FOLDER'] + 'NRDC_data.csv', rows) return render_template('dropPreview.html', column_names=column_names, data_part=data_part)