aboutsummaryrefslogtreecommitdiff
path: root/budget/web.py
diff options
context:
space:
mode:
authorAlexis Metaireau <alexis@notmyidea.org>2011-07-23 19:11:24 +0200
committerAlexis Metaireau <alexis@notmyidea.org>2011-07-23 19:11:24 +0200
commitf09d86a06c9e574679ba32ed27da362ede7cd4f1 (patch)
tree459266b261d492b6962b35af482e747e8084998e /budget/web.py
parentadabd8beec099ffb088bc1b789d7faf08b632ca4 (diff)
downloadihatemoney-mirror-f09d86a06c9e574679ba32ed27da362ede7cd4f1.zip
ihatemoney-mirror-f09d86a06c9e574679ba32ed27da362ede7cd4f1.tar.gz
ihatemoney-mirror-f09d86a06c9e574679ba32ed27da362ede7cd4f1.tar.bz2
Project creation.
Diffstat (limited to 'budget/web.py')
-rw-r--r--budget/web.py71
1 files changed, 44 insertions, 27 deletions
diff --git a/budget/web.py b/budget/web.py
index c96aa8a..d49280c 100644
--- a/budget/web.py
+++ b/budget/web.py
@@ -8,31 +8,6 @@ from utils import get_billform_for, requires_auth
# create the application, initialize stuff
app = Flask(__name__)
-@app.route("/")
-def home():
- return "this is the homepage"
-
-@app.route("/create")
-def create_project():
- form = CreationForm()
- if 'project_id' in request.values:
- form.name.data = request.values['project_id']
-
- if request.method == "POST":
- if form.validate():
- # populate object & redirect
- pass
-
- return render_template("create_project.html", form=form)
-
-@app.route("/<string:project_id>/")
-@requires_auth
-def list_bills(project):
- bills = Bill.query.order_by(Bill.id.asc())
- return render_template("list_bills.html",
- bills=bills, project=project)
-
-
@app.route("/<string:project_id>/authenticate", methods=["GET", "POST"])
def authenticate(project_id, redirect_url=None):
project = Project.query.get(project_id)
@@ -56,10 +31,52 @@ def authenticate(project_id, redirect_url=None):
return render_template("authenticate.html", form=form, project=project)
+@app.route("/")
+def home():
+ # FIXME create a real homepage
+ return "this is the homepage"
+
+@app.route("/create", methods=["GET", "POST"])
+def create_project():
+ from ipdb import set_trace; set_trace()
+ form = CreationForm()
+ if request.method == "GET" and 'project_id' in request.values:
+ form.name.data = request.values['project_id']
+
+ if request.method == "POST":
+ if form.validate():
+ # save the object in the db
+ project = form.save()
+ db.session.add(project)
+ db.session.commit()
+
+ # create the session object (authenticate)
+ session[project.id] = project.password
+ session.update()
+
+ # redirect the user to the next step (invite)
+ return redirect(url_for("invite", project_id=project.id))
+
+ return render_template("create_project.html", form=form)
+
+@app.route("/<string:project_id>/invite")
+@requires_auth
+def invite(project):
+ # FIXME create a real page: form + send emails
+ return "invite ppl"
+
+@app.route("/<string:project_id>/")
+@requires_auth
+def list_bills(project):
+ # FIXME filter to only get the bills for this particular project
+ bills = Bill.query.order_by(Bill.id.asc())
+ return render_template("list_bills.html",
+ bills=bills, project=project)
@app.route("/<string:project_id>/add", methods=["GET", "POST"])
@requires_auth
def add_bill(project):
+ # FIXME: make it work.
form = get_billform_for(project.id)
if request.method == 'POST':
if form.validate():
@@ -72,8 +89,6 @@ def add_bill(project):
bill.owers.append(ower)
db.session.add(bill)
-
-
db.session.commit()
flash("The bill have been added")
return redirect(url_for('list_bills'))
@@ -85,6 +100,7 @@ def add_bill(project):
@requires_auth
def compute_bills(project):
"""Compute the sum each one have to pay to each other and display it"""
+ # FIXME make it work
balances, should_pay, should_receive = {}, {}, {}
# for each person, get the list of should_pay other have for him
@@ -108,6 +124,7 @@ def compute_bills(project):
@requires_auth
def reset_bills(project):
"""Reset the list of bills"""
+ # FIXME replace with the archive feature
# get all the bills which are not processed
bills = Bill.query.filter(Bill.processed == False)
for bill in bills: