1 """The base Controller API
3 Provides the BaseController class for subclassing.
5 from pylons import tmpl_context as c
6 from pylons.controllers import WSGIController
7 from pylons.i18n import _, ungettext, N_
8 from pylons.templating import render_mako as render
10 import bluechips.lib.helpers as h
11 from bluechips import model
12 from bluechips.model import meta
14 from paste.request import construct_url
15 from paste.httpexceptions import HTTPMovedPermanently
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']
24 if environ['pylons.routes_dict']['controller'] != 'error':
25 if environ['PATH_INFO'].endswith('/index'):
26 environ['PATH_INFO'] = environ['PATH_INFO'][:-5]
27 raise HTTPMovedPermanently(construct_url(environ))
28 if not environ['PATH_INFO'].endswith('/') and \
29 environ['pylons.routes_dict']['action'] == 'index':
30 environ['PATH_INFO'] += '/'
31 raise HTTPMovedPermanently(construct_url(environ))
33 return WSGIController.__call__(self, environ, start_response)
37 def update_sar(record, form_result):
39 Update a SQLAlchemy record with the results of a validated form submission
41 for key, value in form_result.items():
42 setattr(record, key, value)
44 __all__ = ['c', 'h', 'render', 'model', 'meta', '_', 'ungettext', 'N_',
45 'BaseController', 'update_sar']