b42d2be4a1a63bd7e30c02a71d0943ad613bbe97
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'])
26 def __call__(self
, environ
, start_response
):
27 """Invoke the Controller"""
28 # WSGIController.__call__ dispatches to the Controller method
29 # the request is routed to. This routing information is
30 # available in environ['pylons.routes_dict']
32 # Insert any code to be run per request here.
35 return WSGIController
.__call__(self
, environ
, start_response
)
37 model
.Session
.remove()
40 def redirect_to_referrer(self
):
41 """Performs a redirect_to to wherever we came from. Used for stuff
44 referrer
= request
.headers
.get('REFERER', '/')
45 redirect(referrer
, code
=302)