g.handle_notification((t.debtor, t.creditor), show, body)
return h.redirect_to('/')
+
+ def delete(self, id):
+ c.title = 'Delete a Transfer'
+ c.transfer = meta.Session.query(model.Transfer).get(id)
+ if c.transfer is None:
+ abort(404)
+
+ return render('/transfer/delete.mako')
+
+ @redirect_on_get('delete')
+ @authenticate_form
+ def destroy(self, id):
+ t = meta.Session.query(model.Transfer).get(id)
+ if t is None:
+ abort(404)
+
+ if 'delete' in request.params:
+ meta.Session.delete(t)
+
+ meta.Session.commit()
+ show = ("Transfer of %s from %s to %s deleted." %
+ (t.amount, t.debtor, t.creditor))
+ h.flash(show)
+
+ body = render('/emails/transfer.txt',
+ extra_vars={'transfer': t,
+ 'op': 'deleted'})
+ g.handle_notification((t.debtor, t.creditor), show, body)
+
+ return h.redirect_to('/')
--- /dev/null
+<%inherit file="/base.mako"/>
+
+<p>Are you sure you want to delete this transfer?</p>
+
+<form action="${h.url_for(controller='transfer', action='destroy', id=c.transfer.id)}" method="post">
+ ${h.auth_token_hidden_field()}
+ <table class="form">
+ <tr>
+ <th><label for="debtor_id">From</label></th>
+ <td>${c.transfer.debtor_id}</td>
+ </tr>
+ <tr>
+ <th><label for="creditor_id">To</label></th>
+ <td>${c.transfer.creditor_id}</td>
+ </tr>
+ <tr>
+ <th><label for="amount">Amount</label></th>
+ <td>${c.transfer.amount}</td>
+ </tr>
+ <tr>
+ <th><label for="date">Date</label></th>
+ <td>${c.transfer.date.strftime('%m/%d/%Y')}</td>
+ </tr>
+ <tr>
+ <th><label for="description">Description</label></th>
+ <td>${c.transfer.description}</td>
+ </tr>
+ <tr>
+ <td colspan="2">
+ ${h.submit('delete', 'Delete', class_="submitbutton")}
+ ${h.submit('cancel', 'Cancel', class_="submitbutton")}
+ </td>
+ </tr>
+ </table>
+</form>