1 """The base Controller API
3 Provides the BaseController class for subclassing.
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
11 from floof
import model
12 from floof
.model
.users
import User
14 class BaseController(WSGIController
):
16 # NOTE: This could have been implemented as a middleware =]
18 c
.route
= request_config().mapper_dict
20 # Fetch current user object
22 c
.user
= User
.query
.get(session
['user_id'])
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']
33 # Insert any code to be run per request here.
36 return WSGIController
.__call__(self
, environ
, start_response
)
38 model
.Session
.remove()
41 def redirect_to_referrer(self
):
42 """Performs a redirect_to to wherever we came from. Used for stuff
45 referrer
= request
.headers
.get('REFERER', '/')
46 redirect(referrer
, code
=302)