Commit 7b4d29269119d2f2529980aaafc96855727f9414
1 parent
3b18543e
Exists in
master
Rework the controllers.
Showing
2 changed files
with
50 additions
and
13 deletions
Show diff stats
... | ... | @@ -0,0 +1,44 @@ |
1 | +from flask import Blueprint, render_template, flash, request, redirect, url_for | |
2 | + | |
3 | +from flaskr.extensions import cache | |
4 | +from flaskr.forms import LoginForm, EstimateForm | |
5 | +from flaskr.models import db, User, Estimation | |
6 | + | |
7 | +from flaskr.core import generate_unique_id | |
8 | + | |
9 | +main = Blueprint('main', __name__) | |
10 | + | |
11 | + | |
12 | +@main.route('/') | |
13 | +@cache.cached(timeout=1000) | |
14 | +def home(): | |
15 | + return render_template('index.html') | |
16 | + | |
17 | + | |
18 | +@main.route("/estimate", methods=["GET", "POST"]) | |
19 | +def estimate(): | |
20 | + form = EstimateForm() | |
21 | + | |
22 | + if form.validate_on_submit(): | |
23 | + | |
24 | + # FIXME: do things here with the form | |
25 | + | |
26 | + id = generate_unique_id() | |
27 | + | |
28 | + # estimation = form.data | |
29 | + | |
30 | + estimation = Estimation() | |
31 | + estimation.email = form.email.data | |
32 | + estimation.first_name = form.first_name.data | |
33 | + estimation.last_name = form.last_name.data | |
34 | + estimation.status = 'pending' | |
35 | + | |
36 | + db.session.add(estimation) | |
37 | + db.session.commit() | |
38 | + | |
39 | + flash("Estimation request submitted successfully.", "success") | |
40 | + return redirect(url_for(".home")) | |
41 | + # return render_template("estimate-debrief.html", form=form) | |
42 | + | |
43 | + return render_template("estimate.html", form=form) | |
44 | + | ... | ... |
flaskr/controllers/main.py renamed to flaskr/controllers/user_controller.py
1 | 1 | from flask import Blueprint, render_template, flash, request, redirect, url_for |
2 | 2 | from flask_login import login_user, logout_user, login_required |
3 | 3 | |
4 | -from flaskr.extensions import cache | |
5 | 4 | from flaskr.forms import LoginForm |
6 | -from flaskr.models import User | |
5 | +from flaskr.models import db, User | |
7 | 6 | |
8 | -main = Blueprint('main', __name__) | |
9 | - | |
10 | - | |
11 | -@main.route('/') | |
12 | -@cache.cached(timeout=1000) | |
13 | -def home(): | |
14 | - return render_template('index.html') | |
7 | +from flaskr.controllers.main_controller import main | |
15 | 8 | |
16 | 9 | |
17 | 10 | @main.route("/login", methods=["GET", "POST"]) |
... | ... | @@ -36,7 +29,7 @@ def logout(): |
36 | 29 | return redirect(url_for(".home")) |
37 | 30 | |
38 | 31 | |
39 | -@main.route("/restricted") | |
40 | -@login_required | |
41 | -def restricted(): | |
42 | - return "You can only see this if you are logged in!", 200 | |
32 | +# @main.route("/restricted") | |
33 | +# @login_required | |
34 | +# def restricted(): | |
35 | +# return "You can only see this if you are logged in!", 200 | ... | ... |