diff --git a/flaskr/controllers/main_controller.py b/flaskr/controllers/main_controller.py index 65f3bb5..9b4347f 100644 --- a/flaskr/controllers/main_controller.py +++ b/flaskr/controllers/main_controller.py @@ -1,6 +1,7 @@ import importlib -from flask import Blueprint, render_template, flash, request, redirect, url_for +from flask import Blueprint, render_template, flash, request, redirect, \ + url_for, abort from flaskr.extensions import cache from flaskr.forms import LoginForm, EstimateForm @@ -10,6 +11,7 @@ from flaskr.geocoder import CachedGeocoder from flaskr.core import generate_unique_id from flaskr.content import content +# from io import StringIO from yaml import safe_dump as yaml_dump import sqlalchemy @@ -33,7 +35,7 @@ def estimate(): id = generate_unique_id() estimation = Estimation() - estimation.email = form.email.data + # estimation.email = form.email.data estimation.first_name = form.first_name.data estimation.last_name = form.last_name.data estimation.status = StatusEnum.pending @@ -45,7 +47,11 @@ def estimate(): db.session.commit() flash("Estimation request submitted successfully.", "success") - return redirect(url_for(".home")) + return redirect(url_for( + endpoint=".consult_estimation", + public_id=estimation.public_id, + format='html' + )) # return render_template("estimate-debrief.html", form=form) return render_template("estimate.html", form=form) @@ -58,7 +64,7 @@ def compute(): # process the queue of estimation requests return "
%s" % _msg def _handle_failure(_estimation, _failure_message): - _estimation.status = StatusEnum.failed + _estimation.status = StatusEnum.failure _estimation.errors = _failure_message db.session.commit() @@ -260,6 +266,62 @@ def compute(): # process the queue of estimation requests else: pass + # WRITE RESULTS INTO THE DATABASE ######################################### + + estimation.status = StatusEnum.success + estimation.output_yaml = yaml_dump(results) + db.session.commit() + + # FINALLY, RESPOND ######################################################## + response += yaml_dump(results) + "\n" return _respond(response) + + +@main.route("/estimation/