##// END OF EJS Templates
change error controller,...
Marcin Kuzminski -
r14:923f0e6a default
parent child Browse files
Show More
@@ -11,9 +11,12 b' debug = true'
11 ## Uncomment and replace with the address ##
11 ## Uncomment and replace with the address ##
12 ## which should receive any error reports ##
12 ## which should receive any error reports ##
13 ############################################
13 ############################################
14 email_to = marcin.kuzminski@etelko.pl
14 #email_to = marcin.kuzminski@etelko.pl
15 smtp_server = localhost
15 #smtp_server = mail.etelko.pl
16 error_email_from = paste_error@localhost
16 #error_email_from = paste_error@localhost
17 #smtp_username =
18 #smtp_password =
19 #error_message = 'mercurial crash !'
17
20
18 [server:main]
21 [server:main]
19 use = egg:Paste#http
22 use = egg:Paste#http
@@ -11,9 +11,12 b' debug = true'
11 ## Uncomment and replace with the address ##
11 ## Uncomment and replace with the address ##
12 ## which should receive any error reports ##
12 ## which should receive any error reports ##
13 ############################################
13 ############################################
14 email_to = marcin.kuzminski@etelko.pl
14 #email_to = marcin.kuzminski@etelko.pl
15 smtp_server = localhost
15 #smtp_server = mail.etelko.pl
16 error_email_from = paste_error@localhost
16 #error_email_from = paste_error@localhost
17 #smtp_username =
18 #smtp_password =
19 #error_message = 'mercurial crash !'
17
20
18 [server:main]
21 [server:main]
19 use = egg:Paste#http
22 use = egg:Paste#http
@@ -22,14 +25,11 b' port = 8001'
22
25
23 [app:main]
26 [app:main]
24 use = egg:pylons_app
27 use = egg:pylons_app
25 full_stack = false
28 full_stack = true
26 static_files = true
29 static_files = true
27 #default lang
28 lang=en
30 lang=en
29
30 cache_dir = %(here)s/data
31 cache_dir = %(here)s/data
31
32
32
33 ################################################################################
33 ################################################################################
34 ## WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT* ##
34 ## WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT* ##
35 ## Debug mode will enable the interactive debugging tool, allowing ANYONE to ##
35 ## Debug mode will enable the interactive debugging tool, allowing ANYONE to ##
@@ -49,9 +49,10 b' def make_app(global_conf, full_stack = T'
49 # Display error documents for 401, 403, 404 status codes (and
49 # Display error documents for 401, 403, 404 status codes (and
50 # 500 when debug is disabled)
50 # 500 when debug is disabled)
51 if asbool(config['debug']):
51 if asbool(config['debug']):
52 app = StatusCodeRedirect(app)
52 #don't handle 404, since mercurial does it for us.
53 app = StatusCodeRedirect(app, [400, 401, 403, 500])
53 else:
54 else:
54 app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])
55 app = StatusCodeRedirect(app, [400, 401, 403, 500])
55
56
56 # Establish the Registry for this application
57 # Establish the Registry for this application
57 app = RegistryManager(app)
58 app = RegistryManager(app)
@@ -1,10 +1,13 b''
1 import logging
1 import logging
2 from paste.urlparser import PkgResourcesParser
2 from paste.urlparser import PkgResourcesParser
3 import paste.fileapp
3 from pylons import request, tmpl_context as c
4 from pylons import request, tmpl_context as c
4 from pylons.controllers.util import forward
5 from pylons.controllers.util import forward
5 from pylons.i18n.translation import _
6 from pylons.i18n.translation import _
6 from pylons_app.lib.base import BaseController, render
7 from pylons_app.lib.base import BaseController, render
8 from pylons.middleware import error_document_template, media_path
7 import cgi
9 import cgi
10 import os
8
11
9 log = logging.getLogger(__name__)
12 log = logging.getLogger(__name__)
10 class ErrorController(BaseController):
13 class ErrorController(BaseController):
@@ -17,28 +20,41 b' class ErrorController(BaseController):'
17 This behaviour can be altered by changing the parameters to the
20 This behaviour can be altered by changing the parameters to the
18 ErrorDocuments middleware in your config/middleware.py file.
21 ErrorDocuments middleware in your config/middleware.py file.
19 """
22 """
23 #
24 def __before__(self):
25 pass
20
26
21 def document(self):
27 def document(self):
22
28
23 resp = request.environ.get('pylons.original_response')
29 resp = request.environ.get('pylons.original_response')
30 log.debug(resp.status)
24 c.error_message = cgi.escape(request.GET.get('code', str(resp.status)))
31 c.error_message = cgi.escape(request.GET.get('code', str(resp.status)))
25 c.error_explanation = self.get_error_explanation(resp.status_int)
32 c.error_explanation = self.get_error_explanation(resp.status_int)
26
33
27 c.serv_p = ''.join(['http://', request.environ.get('HTTP_HOST', '')])
34 c.serv_p = ''.join(['http://', request.environ.get('HTTP_HOST', '')])
28
35
29 #redirect to when error with given seconds
36 #redirect to when error with given seconds
30 c.redirect_time = 5
37 c.redirect_time = 0
31 c.redirect_module = _('Home page')# name to what your going to be redirected
38 c.redirect_module = _('Home page')# name to what your going to be redirected
32 c.url_redirect = "/"
39 c.url_redirect = "/"
33
40
34 return render('/errors/error_document.html')
41 return render('/errors/error_document.html')
35
42
43
44 def img(self, id):
45 """Serve Pylons' stock images"""
46 return self._serve_file(os.path.join(media_path, 'img', id))
47
48 def style(self, id):
49 """Serve Pylons' stock stylesheets"""
50 return self._serve_file(os.path.join(media_path, 'style', id))
51
36 def _serve_file(self, path):
52 def _serve_file(self, path):
37 """Call Paste's FileApp (a WSGI application) to serve the file
53 """Call Paste's FileApp (a WSGI application) to serve the file
38 at the specified path
54 at the specified path
39 """
55 """
40 request.environ['PATH_INFO'] = '/%s' % path
56 fapp = paste.fileapp.FileApp(path)
41 return forward(PkgResourcesParser('pylons', 'pylons'))
57 return fapp(request.environ, self.start_response)
42
58
43 def get_error_explanation(self, code):
59 def get_error_explanation(self, code):
44 ''' get the error explanations of int codes
60 ''' get the error explanations of int codes
@@ -6,14 +6,19 b''
6 <head>
6 <head>
7 <title>Error - ${c.error_message}</title>
7 <title>Error - ${c.error_message}</title>
8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
9
10 %if c.redirect_time:
9 <meta http-equiv="refresh" content="${c.redirect_time}; url=${c.url_redirect}"/>
11 <meta http-equiv="refresh" content="${c.redirect_time}; url=${c.url_redirect}"/>
12 %endif
13
14
10 <style type="text/css">
15 <style type="text/css">
11
16
12 body {
17 body {
13 font-family: sans-serif;
18 font-family: sans-serif;
14 }
19 }
15 #main_div{
20 #main_div{
16 border: 2px solid #8daed8;
21 border: 0px solid #000;
17 width: 500px;
22 width: 500px;
18 margin: auto;
23 margin: auto;
19 text-align: center;
24 text-align: center;
@@ -31,7 +36,10 b''
31 <h1 class="error_message">${c.error_message}</h1>
36 <h1 class="error_message">${c.error_message}</h1>
32
37
33 <p>${c.error_explanation}</p>
38 <p>${c.error_explanation}</p>
39 %if c.redirect_time:
34 <p>${_('You will be redirected to %s in %s seconds') % (c.redirect_module,c.redirect_time)}</p>
40 <p>${_('You will be redirected to %s in %s seconds') % (c.redirect_module,c.redirect_time)}</p>
41 %endif
42
35 </div>
43 </div>
36 </body>
44 </body>
37 </html>
45 </html>
General Comments 0
You need to be logged in to leave comments. Login now