yolanda/trunk/yolanda/controllers/error.py
erlehmann bffdb722ac going pylons !
git-svn-id: http://yolanda.mister-muffin.de/svn@362 7eef14d0-6ed0-489d-bf55-20463b2d70db
2008-07-31 19:19:08 +00:00

39 lines
1.3 KiB
Python

import os.path
import paste.fileapp
from pylons.middleware import error_document_template, media_path
from yolanda.lib.base import *
class ErrorController(BaseController):
"""Generates error documents as and when they are required.
The ErrorDocuments middleware forwards to ErrorController when error
related status codes are returned from the application.
This behaviour can be altered by changing the parameters to the
ErrorDocuments middleware in your config/middleware.py file.
"""
def document(self):
"""Render the error document"""
page = error_document_template % \
dict(prefix=request.environ.get('SCRIPT_NAME', ''),
code=request.params.get('code', ''),
message=request.params.get('message', ''))
return page
def img(self, id):
"""Serve Pylons' stock images"""
return self._serve_file(os.path.join(media_path, 'img', id))
def style(self, id):
"""Serve Pylons' stock stylesheets"""
return self._serve_file(os.path.join(media_path, 'style', id))
def _serve_file(self, path):
"""Call Paste's FileApp (a WSGI application) to serve the file
at the specified path
"""
fapp = paste.fileapp.FileApp(path)
return fapp(request.environ, self.start_response)