Fixed adding regular tags.
[zzz-floof.git] / floof / controllers / error.py
1 import cgi
2
3 from paste.urlparser import PkgResourcesParser
4 from pylons import request
5 from pylons.controllers.util import forward
6 from pylons.middleware import error_document_template
7 from webhelpers.html.builder import literal
8
9 from floof.lib.base import BaseController
10
11 class ErrorController(BaseController):
12
13 """Generates error documents as and when they are required.
14
15 The ErrorDocuments middleware forwards to ErrorController when error
16 related status codes are returned from the application.
17
18 This behaviour can be altered by changing the parameters to the
19 ErrorDocuments middleware in your config/middleware.py file.
20
21 """
22
23 def document(self):
24 """Render the error document"""
25 resp = request.environ.get('pylons.original_response')
26 content = literal(resp.body) or cgi.escape(request.GET.get('message', ''))
27 page = error_document_template % \
28 dict(prefix=request.environ.get('SCRIPT_NAME', ''),
29 code=cgi.escape(request.GET.get('code', str(resp.status_int))),
30 message=content)
31 return page
32
33 def img(self, id):
34 """Serve Pylons' stock images"""
35 return self._serve_file('/'.join(['media/img', id]))
36
37 def style(self, id):
38 """Serve Pylons' stock stylesheets"""
39 return self._serve_file('/'.join(['media/style', id]))
40
41 def _serve_file(self, path):
42 """Call Paste's FileApp (a WSGI application) to serve the file
43 at the specified path
44 """
45 request.environ['PATH_INFO'] = '/%s' % path
46 return forward(PkgResourcesParser('pylons', 'pylons'))