From 922bf769f99ab6755c04dc62caab5f91353d4d73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Sureau?= Date: Wed, 10 Aug 2011 12:59:30 +0200 Subject: It is now possible to edit existing bills. --- budget/web.py | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) (limited to 'budget/web.py') diff --git a/budget/web.py b/budget/web.py index 24a034b..601ee81 100644 --- a/budget/web.py +++ b/budget/web.py @@ -166,15 +166,45 @@ def add_bill(project): form = get_billform_for(project) if request.method == 'POST': if form.validate(): - db.session.add(form.save()) + bill = Bill() + db.session.add(form.save(bill)) db.session.commit() flash("The bill has been added") return redirect(url_for('list_bills', project_id=project.id)) + form.set_default() return render_template("add_bill.html", form=form, project=project) +@app.route("//delete/") +@requires_auth +def delete_bill(project, bill_id): + bill = Bill.query.get_or_404(bill_id) + db.session.delete(bill) + # FIXME Delete also billowers relations + db.session.commit() + flash("The bill has been deleted") + + return redirect(url_for('list_bills', project_id=project.id)) + + +@app.route("//edit/", methods=["GET", "POST"]) +@requires_auth +def edit_bill(project, bill_id): + bill = Bill.query.get_or_404(bill_id) + form = get_billform_for(project) + if request.method == 'POST' and form.validate(): + # FIXME Edit also billowers relations + form.save(bill) + db.session.commit() + + flash("The bill has been modified") + return redirect(url_for('list_bills', project_id=project.id)) + + form.fill(bill) + return render_template("edit_bill.html", form=form, project=project, bill_id=bill_id) + @app.route("//compute") @requires_auth def compute_bills(project): @@ -196,17 +226,6 @@ def reset_bills(project): return redirect(url_for('list_bills')) -@app.route("//delete/") -@requires_auth -def delete_bill(project, bill_id): - Bill.query.filter(Bill.id == bill_id).delete() - BillOwer.query.filter(BillOwer.bill_id == bill_id).delete() - db.session.commit() - flash("the bill was deleted") - - return redirect(url_for('list_bills')) - - def main(): app.run(host="0.0.0.0", debug=True) -- cgit v1.1