##// END OF EJS Templates
spelling fixes for error controller
marcink -
r819:f579790a beta
parent child Browse files
Show More
@@ -1,85 +1,110 b''
1 import logging
1 # -*- coding: utf-8 -*-
2 """
3 package.rhodecode.controllers.error
4 ~~~~~~~~~~~~~~
5
6 RhodeCode error controller
7
8 :created_on: Dec 8, 2010
9 :author: marcink
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
12 """
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation; version 2
16 # of the License or (at your opinion) any later version of the license.
17 #
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 # MA 02110-1301, USA.
27 import os
2 import cgi
28 import cgi
3 import os
29 import logging
4 import paste.fileapp
30 import paste.fileapp
5 from pylons import tmpl_context as c, app_globals as g, request, config
31
6 from pylons.controllers.util import forward
32 from pylons import tmpl_context as c, request
7 from pylons.i18n.translation import _
33 from pylons.i18n.translation import _
34 from pylons.middleware import media_path
35
8 from rhodecode.lib.base import BaseController, render
36 from rhodecode.lib.base import BaseController, render
9 from pylons.middleware import media_path
37
10 from rhodecode.lib.utils import check_repo
11 import rhodecode.lib.helpers as h
12 from rhodecode import __version__
13 log = logging.getLogger(__name__)
38 log = logging.getLogger(__name__)
14
39
15 class ErrorController(BaseController):
40 class ErrorController(BaseController):
16 """
41 """Generates error documents as and when they are required.
17 Generates error documents as and when they are required.
18
42
19 The ErrorDocuments middleware forwards to ErrorController when error
43 The ErrorDocuments middleware forwards to ErrorController when error
20 related status codes are returned from the application.
44 related status codes are returned from the application.
21
45
22 This behaviour can be altered by changing the parameters to the
46 This behavior can be altered by changing the parameters to the
23 ErrorDocuments middleware in your config/middleware.py file.
47 ErrorDocuments middleware in your config/middleware.py file.
24 """
48 """
49
25 def __before__(self):
50 def __before__(self):
26 pass#disable all base actions since we don't need them here
51 pass#disable all base actions since we don't need them here
27
52
28 def document(self):
53 def document(self):
29 resp = request.environ.get('pylons.original_response')
54 resp = request.environ.get('pylons.original_response')
30
55
31 log.debug('### %s ###', resp.status)
56 log.debug('### %s ###', resp.status)
32
57
33 e = request.environ
58 e = request.environ
34 c.serv_p = r'%(protocol)s://%(host)s/' % {
59 c.serv_p = r'%(protocol)s://%(host)s/' % {
35 'protocol': e.get('wsgi.url_scheme'),
60 'protocol': e.get('wsgi.url_scheme'),
36 'host':e.get('HTTP_HOST'),
61 'host':e.get('HTTP_HOST'),
37 }
62 }
38
63
39
64
40 c.error_message = cgi.escape(request.GET.get('code', str(resp.status)))
65 c.error_message = cgi.escape(request.GET.get('code', str(resp.status)))
41 c.error_explanation = self.get_error_explanation(resp.status_int)
66 c.error_explanation = self.get_error_explanation(resp.status_int)
42
67
43 #redirect to when error with given seconds
68 #redirect to when error with given seconds
44 c.redirect_time = 0
69 c.redirect_time = 0
45 c.redirect_module = _('Home page')# name to what your going to be redirected
70 c.redirect_module = _('Home page')# name to what your going to be redirected
46 c.url_redirect = "/"
71 c.url_redirect = "/"
47
72
48 return render('/errors/error_document.html')
73 return render('/errors/error_document.html')
49
74
50
75
51 def img(self, id):
76 def img(self, id):
52 """Serve Pylons' stock images"""
77 """Serve Pylons' stock images"""
53 return self._serve_file(os.path.join(media_path, 'img', id))
78 return self._serve_file(os.path.join(media_path, 'img', id))
54
79
55 def style(self, id):
80 def style(self, id):
56 """Serve Pylons' stock stylesheets"""
81 """Serve Pylons' stock stylesheets"""
57 return self._serve_file(os.path.join(media_path, 'style', id))
82 return self._serve_file(os.path.join(media_path, 'style', id))
58
83
59 def _serve_file(self, path):
84 def _serve_file(self, path):
60 """Call Paste's FileApp (a WSGI application) to serve the file
85 """Call Paste's FileApp (a WSGI application) to serve the file
61 at the specified path
86 at the specified path
62 """
87 """
63 fapp = paste.fileapp.FileApp(path)
88 fapp = paste.fileapp.FileApp(path)
64 return fapp(request.environ, self.start_response)
89 return fapp(request.environ, self.start_response)
65
90
66 def get_error_explanation(self, code):
91 def get_error_explanation(self, code):
67 ''' get the error explanations of int codes
92 ''' get the error explanations of int codes
68 [400, 401, 403, 404, 500]'''
93 [400, 401, 403, 404, 500]'''
69 try:
94 try:
70 code = int(code)
95 code = int(code)
71 except:
96 except:
72 code = 500
97 code = 500
73
98
74 if code == 400:
99 if code == 400:
75 return _('The request could not be understood by the server due to malformed syntax.')
100 return _('The request could not be understood by the server due to malformed syntax.')
76 if code == 401:
101 if code == 401:
77 return _('Unathorized access to resource')
102 return _('Unauthorized access to resource')
78 if code == 403:
103 if code == 403:
79 return _("You don't have permission to view this page")
104 return _("You don't have permission to view this page")
80 if code == 404:
105 if code == 404:
81 return _('The resource could not be found')
106 return _('The resource could not be found')
82 if code == 500:
107 if code == 500:
83 return _('The server encountered an unexpected condition which prevented it from fulfilling the request.')
108 return _('The server encountered an unexpected condition which prevented it from fulfilling the request.')
84
109
85
110
General Comments 0
You need to be logged in to leave comments. Login now