169493c38ddeb2d2a8c378686512209caab02fc8
[zzz-floof.git] / floof / lib / base.py
1 """The base Controller API
2
3 Provides the BaseController class for subclassing.
4 """
5 from pylons.controllers import WSGIController
6 from pylons.templating import render_mako as render
7 from pylons import config, session, tmpl_context as c
8 from routes import request_config
9
10 from floof import model
11 from floof.model.users import User
12
13 class BaseController(WSGIController):
14
15 # NOTE: This could have been implemented as a middleware =]
16 def __before__(self):
17 c.route = request_config().mapper_dict
18
19 # Fetch current user object
20 try:
21 c.user = User.query.get(session['user_id'])
22 except:
23 pass
24
25 def __call__(self, environ, start_response):
26 """Invoke the Controller"""
27 # WSGIController.__call__ dispatches to the Controller method
28 # the request is routed to. This routing information is
29 # available in environ['pylons.routes_dict']
30
31 # Insert any code to be run per request here.
32
33 try:
34 return WSGIController.__call__(self, environ, start_response)
35 finally:
36 model.Session.remove()