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
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
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']