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_
9 from tw.mods.pylonshf import render, render_response, validate
11 import bluechips.lib.helpers as h
12 from bluechips import model
13 from bluechips.model import meta
15 from paste.request import construct_url
16 from paste.httpexceptions import HTTPMovedPermanently
18 class BaseController(WSGIController):
20 def __call__(self, environ, start_response):
21 """Invoke the Controller"""
22 # WSGIController.__call__ dispatches to the Controller method
23 # the request is routed to. This routing information is
24 # available in environ['pylons.routes_dict']
25 if environ['pylons.routes_dict']['controller'] != 'error':
26 if environ['PATH_INFO'].endswith('/index'):
27 environ['PATH_INFO'] = environ['PATH_INFO'][:-5]
28 raise HTTPMovedPermanently(construct_url(environ))
29 if not environ['PATH_INFO'].endswith('/') and \
30 environ['pylons.routes_dict']['action'] == 'index':
31 environ['PATH_INFO'] += '/'
32 raise HTTPMovedPermanently(construct_url(environ))
34 return WSGIController.__call__(self, environ, start_response)
38 def update_sar(record, form_result):
40 Update a SQLAlchemy record with the results of a validated form submission
42 for key, value in form_result.items():
43 setattr(record, key, value)
45 __all__ = ['c', 'h', 'render', 'render_response', 'validate',
46 'model', 'meta', '_', 'ungettext', 'N_', 'BaseController',