1 """The base Controller API
3 Provides the BaseController class for subclassing.
5 from decorator import decorator
7 from pylons import request, tmpl_context as c
8 from pylons.controllers import WSGIController
9 from pylons.i18n import _, ungettext, N_
10 from pylons.templating import render_mako as render
12 import bluechips.lib.helpers as h
13 from bluechips import model
14 from bluechips.model import meta
17 class BaseController(WSGIController):
19 def __call__(self, environ, start_response):
20 """Invoke the Controller"""
21 # WSGIController.__call__ dispatches to the Controller method
22 # the request is routed to. This routing information is
23 # available in environ['pylons.routes_dict']
25 return WSGIController.__call__(self, environ, start_response)
29 def update_sar(record, form_result):
31 Update a SQLAlchemy record with the results of a validated form submission
33 for key, value in form_result.items():
34 setattr(record, key, value)
36 def redirect_on_get(action):
38 Decorator for a controller action. If the action is called with a GET
39 method, 302 redirect to the action specified.
43 def redirect_on_get_wrap(func, *args, **kwargs):
44 if request.method == 'GET':
45 controller = request.environ['pylons.routes_dict']['controller']
46 return h.redirect_to(controller=controller, action=action)
48 return func(*args, **kwargs)
49 return redirect_on_get_wrap
52 __all__ = ['c', 'h', 'render', 'model', 'meta', '_', 'ungettext', 'N_',
53 'BaseController', 'update_sar', 'redirect_on_get']