]> asedeno.scripts.mit.edu Git - bluechips.git/blob - bluechips/lib/base.py
Routes components are Unicode strings, so fix the URL universalizer
[bluechips.git] / bluechips / lib / base.py
1 """The base Controller API
2
3 Provides the BaseController class for subclassing.
4 """
5 from pylons import tmpl_context as c
6 from pylons.controllers import WSGIController
7 from pylons.i18n import _, ungettext, N_
8
9 from tw.mods.pylonshf import render, render_response, validate
10
11 import bluechips.lib.helpers as h
12 from bluechips import model
13 from bluechips.model import meta
14
15 from paste.request import construct_url
16 from paste.httpexceptions import HTTPMovedPermanently
17
18 class BaseController(WSGIController):
19
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))
33         try:
34             return WSGIController.__call__(self, environ, start_response)
35         finally:
36             meta.Session.remove()
37
38 __all__ = ['c', 'h', 'render', 'render_response', 'validate',
39            'model', 'meta', '_', 'ungettext', 'N_', 'BaseController']