diff options
| author | Frédéric Sureau <fred@milka.(none)> | 2011-08-10 12:59:30 +0200 |
|---|---|---|
| committer | Frédéric Sureau <fred@milka.(none)> | 2011-08-10 12:59:30 +0200 |
| commit | 922bf769f99ab6755c04dc62caab5f91353d4d73 (patch) | |
| tree | 44a00ca957c852c742c72390c2bebcb1a160f6e0 /budget/web.py | |
| parent | af2ca220a76d6ffe58d37e52a67f263b8905ed60 (diff) | |
| download | ihatemoney-mirror-922bf769f99ab6755c04dc62caab5f91353d4d73.zip ihatemoney-mirror-922bf769f99ab6755c04dc62caab5f91353d4d73.tar.gz ihatemoney-mirror-922bf769f99ab6755c04dc62caab5f91353d4d73.tar.bz2 | |
It is now possible to edit existing bills.
Diffstat (limited to 'budget/web.py')
| -rw-r--r-- | budget/web.py | 43 |
1 files changed, 31 insertions, 12 deletions
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("/<string:project_id>/delete/<int:bill_id>") +@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("/<string:project_id>/edit/<int:bill_id>", 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("/<string:project_id>/compute") @requires_auth def compute_bills(project): @@ -196,17 +226,6 @@ def reset_bills(project): return redirect(url_for('list_bills')) -@app.route("/<string:project_id>/delete/<int:bill_id>") -@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) |
