]> asedeno.scripts.mit.edu Git - bluechips.git/commitdiff
Add an action for deleting transfers.
authorEvan Broder <broder@mit.edu>
Mon, 9 Nov 2009 02:08:26 +0000 (21:08 -0500)
committerEvan Broder <broder@mit.edu>
Mon, 9 Nov 2009 02:09:14 +0000 (21:09 -0500)
bluechips/controllers/transfer.py
bluechips/templates/transfer/delete.mako [new file with mode: 0644]

index ed0601845fc58b9db6f8ad67bfd1daf1e10d0702..5c147bc35456a97a3b70ae439929d2291f62020d 100644 (file)
@@ -75,3 +75,33 @@ class TransferController(BaseController):
         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('/')
diff --git a/bluechips/templates/transfer/delete.mako b/bluechips/templates/transfer/delete.mako
new file mode 100644 (file)
index 0000000..0475c8b
--- /dev/null
@@ -0,0 +1,35 @@
+<%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>