Fixed adding regular tags.
[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.controllers.util import abort, redirect
7 from pylons.templating import render_mako as render
8 from pylons import config, request, session, tmpl_context as c
9 from routes import request_config
10
11 from floof import model
12 from floof.model.users import User
13
14 class BaseController(WSGIController):
15
16 # NOTE: This could have been implemented as a middleware =]
17 def __before__(self):
18 c.route = request_config().mapper_dict
19
20 # Fetch current user object
21 try:
22 c.user = User.query.get(session['user_id'])
23 except:
24 c.user = None
25 pass
26
27 def __call__(self, environ, start_response):
28 """Invoke the Controller"""
29 # WSGIController.__call__ dispatches to the Controller method
30 # the request is routed to. This routing information is
31 # available in environ['pylons.routes_dict']
32
33 # Insert any code to be run per request here.
34
35 try:
36 return WSGIController.__call__(self, environ, start_response)
37 finally:
38 model.Session.remove()
39
40
41 def redirect_to_referrer(self):
42 """Performs a redirect_to to wherever we came from. Used for stuff
43 like logging in.
44 """
45 referrer = request.headers.get('REFERER', '/')
46 redirect(referrer, code=302)