aboutsummaryrefslogtreecommitdiff
path: root/budget/web.py
diff options
context:
space:
mode:
authorAlexis Metaireau <alexis@notmyidea.org>2011-08-21 01:42:10 +0200
committerAlexis Metaireau <alexis@notmyidea.org>2011-08-21 01:42:10 +0200
commit7d60bee0ef5a38e6765b9bb51ae7e200157591a0 (patch)
tree5437408338e576c339bc402e029cc67589982191 /budget/web.py
parent95fb9bbbfd0636766bb94a6bffdf67deb1172a12 (diff)
downloadihatemoney-mirror-7d60bee0ef5a38e6765b9bb51ae7e200157591a0.zip
ihatemoney-mirror-7d60bee0ef5a38e6765b9bb51ae7e200157591a0.tar.gz
ihatemoney-mirror-7d60bee0ef5a38e6765b9bb51ae7e200157591a0.tar.bz2
Re-design (Fixes #19)
Diffstat (limited to 'budget/web.py')
-rw-r--r--budget/web.py64
1 files changed, 32 insertions, 32 deletions
diff --git a/budget/web.py b/budget/web.py
index 2c48318..fdb33a9 100644
--- a/budget/web.py
+++ b/budget/web.py
@@ -23,12 +23,30 @@ db.create_all()
mail.init_app(app)
-@app.route("/")
-def home():
- project_form = ProjectForm()
- auth_form = AuthenticationForm()
- return render_template("home.html", project_form=project_form,
- auth_form=auth_form, session=session)
+@app.url_defaults
+def add_project_id(endpoint, values):
+ if 'project_id' in values or not hasattr(g, 'project'):
+ return
+ if app.url_map.is_endpoint_expecting(endpoint, 'project_id'):
+ values['project_id'] = g.project.id
+
+@app.url_value_preprocessor
+def pull_project(endpoint, values):
+ if not values:
+ values = {}
+ project_id = values.pop('project_id', None)
+ if project_id:
+ project = Project.query.get(project_id)
+ if not project:
+ raise RequestRedirect(url_for("create_project", project_id=project_id))
+ if project.id in session and session[project.id] == project.password:
+ # add project into kwargs and call the original function
+ g.project = project
+ else:
+ # redirect to authentication page
+ raise RequestRedirect(
+ url_for("authenticate", redirect_url=request.url,
+ project_id=project_id))
@app.route("/authenticate", methods=["GET", "POST"])
def authenticate(redirect_url=None, project_id=None):
@@ -68,6 +86,13 @@ def authenticate(redirect_url=None, project_id=None):
return render_template("authenticate.html", form=form,
create_project=create_project)
+@app.route("/")
+def home():
+ project_form = ProjectForm()
+ auth_form = AuthenticationForm()
+ return render_template("home.html", project_form=project_form,
+ auth_form=auth_form, session=session)
+
@app.route("/create", methods=["GET", "POST"])
def create_project():
form = ProjectForm()
@@ -96,31 +121,6 @@ def exit():
session.clear()
return redirect(url_for("home"))
-@app.url_defaults
-def add_project_id(endpoint, values):
- if 'project_id' in values or not hasattr(g, 'project'):
- return
- if app.url_map.is_endpoint_expecting(endpoint, 'project_id'):
- values['project_id'] = g.project.id
-
-@app.url_value_preprocessor
-def pull_project(endpoint, values):
- if not values:
- values = {}
- project_id = values.pop('project_id', None)
- if project_id:
- project = Project.query.get(project_id)
- if not project:
- raise RequestRedirect(url_for("create_project", project_id=project_id))
- if project.id in session and session[project.id] == project.password:
- # add project into kwargs and call the original function
- g.project = project
- else:
- # redirect to authentication page
- raise RequestRedirect(
- url_for("authenticate", redirect_url=request.url,
- project_id=project_id))
-
@app.route("/<project_id>/invite", methods=["GET", "POST"])
def invite():
@@ -217,7 +217,7 @@ def edit_bill(bill_id):
return redirect(url_for('list_bills'))
form.fill(bill)
- return render_template("edit_bill.html", form=form, bill_id=bill_id)
+ return render_template("add_bill.html", form=form, edit=True)
@app.route("/<project_id>/compute")
def compute_bills():