def upload_form(): success_msg = None app_ctx = AppContext() form = FileUploadForm() if form.validate_on_submit(): (filename, output_f) = generate_file(app.config["NMEA_FILE_UPLOAD_DIR"]) if not filename: abort(500) form.data_file.data.save(output_f) output_f.close() if do_file_loading(g.db, # TODO, should user user's id directly # and not e-mail. InputInfo(user_email=current_user.get_email(), input_file=filename, trip_name=form.trip_name.data, trip_date=form.trip_date.data, vessel_name=form.vessel_name.data), context=app_ctx): success_msg = "File uploaded successfully" else: success_msg = app_ctx.get_log_msgs() return render_template("upload_form.html", success_msg=success_msg, error_msg=app_ctx.get_error_msgs(), form=form, vars=TemplateVars(app))
def update_trip(trip_id): form = TripDataForm() app_ctx = AppContext() if form.validate_on_submit() and \ db_trip_info_update(g.db, trip_id, form.trip_name.data, form.trip_date.data, form.vessel_name.data): return redirect(url_for("trip_map")) if request.method == "GET": trip_data = db_trip_info_fetch(g.db, trip_id) if trip_data: form.trip_name.process_data(trip_data['trip_name'].decode("utf8")) form.trip_date.process_data(trip_data['trip_date'].decode("utf8")) form.vessel_name.process_data(trip_data['vessel_name'].decode("utf8")) return render_template("update_form.html", error_msg=app_ctx.get_error_msgs(), form=form, vars=TemplateVars(app))