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 from tw.mods.pylonshf import validate, valid
12 import bluechips.lib.helpers as h
13 from bluechips import model
14 from bluechips.model import meta
16 from paste.request import construct_url
17 from paste.httpexceptions import HTTPMovedPermanently
19 class BaseController(WSGIController):
21 def __call__(self, environ, start_response):
22 """Invoke the Controller"""
23 # WSGIController.__call__ dispatches to the Controller method
24 # the request is routed to. This routing information is
25 # available in environ['pylons.routes_dict']
26 if environ['pylons.routes_dict']['controller'] != 'error':
27 if environ['PATH_INFO'].endswith('/index'):
28 environ['PATH_INFO'] = environ['PATH_INFO'][:-5]
29 raise HTTPMovedPermanently(construct_url(environ))
30 if not environ['PATH_INFO'].endswith('/') and \
31 environ['pylons.routes_dict']['action'] == 'index':
32 environ['PATH_INFO'] += '/'
33 raise HTTPMovedPermanently(construct_url(environ))
35 c.user = meta.Session.query(model.User).\
36 filter_by(username=unicode(environ['REMOTE_USER'])).one()
37 return WSGIController.__call__(self, environ, start_response)
41 def update_sar(record, form_result):
43 Update a SQLAlchemy record with the results of a validated form submission
45 for key, value in form_result.items():
46 setattr(record, key, value)
48 __all__ = ['c', 'h', 'render', 'validate', 'valid',
49 'model', 'meta', '_', 'ungettext', 'N_', 'BaseController',