From 375bf23b86666583e923b02ec2546cad52f5662d Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Sun, 8 Nov 2009 20:50:30 -0500 Subject: [PATCH] Add a new action for deleting expenditures. --- bluechips/controllers/spend.py | 32 +++++++++++++++++++++++++++ bluechips/templates/spend/delete.mako | 31 ++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 bluechips/templates/spend/delete.mako diff --git a/bluechips/controllers/spend.py b/bluechips/controllers/spend.py index 098ac27..4e89b35 100644 --- a/bluechips/controllers/spend.py +++ b/bluechips/controllers/spend.py @@ -132,3 +132,35 @@ class SpendController(BaseController): g.handle_notification(involved_users, show, body) return h.redirect_to('/') + + def delete(self, id): + c.title = 'Delete an Expenditure' + c.expenditure = meta.Session.query(model.Expenditure).get(id) + if c.expenditure is None: + abort(404) + + return render('/spend/delete.mako') + + @redirect_on_get('delete') + @authenticate_form + def destroy(self, id): + e = meta.Session.query(model.Expenditure).get(id) + if e is None: + abort(404) + + if 'delete' in request.params: + meta.Session.delete(e) + + meta.Session.commit() + show = ("Expenditure of %s paid for by %s deleted." % + (e.amount, e.spender)) + h.flash(show) + + involved_users = set(sp.user for sp in e.splits if sp.share != 0) + involved_users.add(e.spender) + body = render('/emails/expenditure.txt', + extra_vars={'expenditure': e, + 'op': 'deleted'}) + g.handle_notification(involved_users, show, body) + + return h.redirect_to('/') diff --git a/bluechips/templates/spend/delete.mako b/bluechips/templates/spend/delete.mako new file mode 100644 index 0000000..19ae422 --- /dev/null +++ b/bluechips/templates/spend/delete.mako @@ -0,0 +1,31 @@ +<%inherit file="/base.mako"/> + +

Are you sure you want to delete this expenditure?

+ +
+ ${h.auth_token_hidden_field()} + + + + + + + + + + + + + + + + + + + + +
${c.expenditure.spender.name}
${c.expenditure.amount}
${c.expenditure.date.strftime('%m/%d/%Y')}
${c.expenditure.description}
+ ${h.submit('delete', 'Delete', class_="submitbutton")} + ${h.submit('cancel', 'Cancel', class_="submitbutton")} +
+
-- 2.45.2