]> asedeno.scripts.mit.edu Git - bluechips.git/commitdiff
if we GET to an update action, redirect to the edit action
authorScott Torborg <scott@crookedmedia.com>
Fri, 6 Nov 2009 03:59:52 +0000 (17:59 -1000)
committerScott Torborg <scott@crookedmedia.com>
Fri, 6 Nov 2009 03:59:54 +0000 (17:59 -1000)
bluechips/controllers/spend.py
bluechips/controllers/transfer.py
bluechips/lib/base.py

index cc6466fed32f95ef15365e9bc86ec53079773dc2..8d2dc4a526e182f8f80430babb5be0452b53da78 100644 (file)
@@ -93,6 +93,7 @@ class SpendController(BaseController):
 
         return render('/spend/index.mako')
 
+    @redirect_on_get('edit')
     @validate(schema=ExpenditureSchema(), form='edit', variable_decode=True)
     def update(self, id=None):
         # Either create a new object, or, if we're editing, get the
index 5aa8be20601ad651d978db51f48de37f20abe352..50948456fad832da5bd81035aee1ea08a6d15d8c 100644 (file)
@@ -47,6 +47,7 @@ class TransferController(BaseController):
                 abort(404)
         return render('/transfer/index.mako')
     
+    @redirect_on_get('edit')
     @validate(schema=TransferSchema(), form='edit')
     def update(self, id=None):
         if id is None:
index 19129d432671a110d4186fad7873f4d4d70e8f76..586336c3a351ff1c25ce3f14f01624601cc8d03e 100644 (file)
@@ -2,7 +2,9 @@
 
 Provides the BaseController class for subclassing.
 """
-from pylons import tmpl_context as c
+from decorator import decorator
+
+from pylons import request, tmpl_context as c
 from pylons.controllers import WSGIController
 from pylons.i18n import _, ungettext, N_
 from pylons.templating import render_mako as render
@@ -31,5 +33,21 @@ def update_sar(record, form_result):
     for key, value in form_result.items():
         setattr(record, key, value)
 
+def redirect_on_get(action):
+    """
+    Decorator for a controller action. If the action is called with a GET
+    method, 302 redirect to the action specified.
+    """
+
+    @decorator
+    def redirect_on_get_wrap(func, *args, **kwargs):
+        if request.method == 'GET':
+            controller = request.environ['pylons.routes_dict']['controller']
+            return h.redirect_to(controller=controller, action=action)
+        else:
+            return func(*args, **kwargs)
+    return redirect_on_get_wrap
+
+
 __all__ = ['c', 'h', 'render', 'model', 'meta', '_', 'ungettext', 'N_',
-           'BaseController', 'update_sar']
+           'BaseController', 'update_sar', 'redirect_on_get']