Mercurial > kallithea
comparison rhodecode/controllers/error.py @ 1212:50e41777675d beta
pep8ify
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 05 Apr 2011 13:12:38 +0200 |
parents | a671db5bdd58 |
children | bf263968da47 89efedac4e6c |
comparison
equal
deleted
inserted
replaced
1211:a7e7c0fab9db | 1212:50e41777675d |
---|---|
25 import os | 25 import os |
26 import cgi | 26 import cgi |
27 import logging | 27 import logging |
28 import paste.fileapp | 28 import paste.fileapp |
29 | 29 |
30 from pylons import tmpl_context as c, request, config | 30 from pylons import tmpl_context as c, request, config, url |
31 from pylons.i18n.translation import _ | 31 from pylons.i18n.translation import _ |
32 from pylons.middleware import media_path | 32 from pylons.middleware import media_path |
33 | 33 |
34 from rhodecode.lib.base import BaseController, render | 34 from rhodecode.lib.base import BaseController, render |
35 | 35 |
36 log = logging.getLogger(__name__) | 36 log = logging.getLogger(__name__) |
37 | |
37 | 38 |
38 class ErrorController(BaseController): | 39 class ErrorController(BaseController): |
39 """Generates error documents as and when they are required. | 40 """Generates error documents as and when they are required. |
40 | 41 |
41 The ErrorDocuments middleware forwards to ErrorController when error | 42 The ErrorDocuments middleware forwards to ErrorController when error |
44 This behavior can be altered by changing the parameters to the | 45 This behavior can be altered by changing the parameters to the |
45 ErrorDocuments middleware in your config/middleware.py file. | 46 ErrorDocuments middleware in your config/middleware.py file. |
46 """ | 47 """ |
47 | 48 |
48 def __before__(self): | 49 def __before__(self): |
49 pass#disable all base actions since we don't need them here | 50 #disable all base actions since we don't need them here |
51 pass | |
50 | 52 |
51 def document(self): | 53 def document(self): |
52 resp = request.environ.get('pylons.original_response') | 54 resp = request.environ.get('pylons.original_response') |
53 c.rhodecode_name = config.get('rhodecode_title') | 55 c.rhodecode_name = config.get('rhodecode_title') |
54 | 56 |
55 log.debug('### %s ###', resp.status) | 57 log.debug('### %s ###', resp.status) |
56 | 58 |
57 e = request.environ | 59 e = request.environ |
58 c.serv_p = r'%(protocol)s://%(host)s/' % { | 60 c.serv_p = r'%(protocol)s://%(host)s/' \ |
59 'protocol': e.get('wsgi.url_scheme'), | 61 % {'protocol': e.get('wsgi.url_scheme'), |
60 'host':e.get('HTTP_HOST'), | 62 'host': e.get('HTTP_HOST'), } |
61 } | |
62 | |
63 | 63 |
64 c.error_message = cgi.escape(request.GET.get('code', str(resp.status))) | 64 c.error_message = cgi.escape(request.GET.get('code', str(resp.status))) |
65 c.error_explanation = self.get_error_explanation(resp.status_int) | 65 c.error_explanation = self.get_error_explanation(resp.status_int) |
66 | 66 |
67 #redirect to when error with given seconds | 67 # redirect to when error with given seconds |
68 c.redirect_time = 0 | 68 c.redirect_time = 0 |
69 c.redirect_module = _('Home page')# name to what your going to be redirected | 69 c.redirect_module = _('Home page') |
70 c.url_redirect = "/" | 70 c.url_redirect = "/" |
71 | 71 |
72 return render('/errors/error_document.html') | 72 return render('/errors/error_document.html') |
73 | |
74 | 73 |
75 def img(self, id): | 74 def img(self, id): |
76 """Serve Pylons' stock images""" | 75 """Serve Pylons' stock images""" |
77 return self._serve_file(os.path.join(media_path, 'img', id)) | 76 return self._serve_file(os.path.join(media_path, 'img', id)) |
78 | 77 |
94 code = int(code) | 93 code = int(code) |
95 except: | 94 except: |
96 code = 500 | 95 code = 500 |
97 | 96 |
98 if code == 400: | 97 if code == 400: |
99 return _('The request could not be understood by the server due to malformed syntax.') | 98 return _('The request could not be understood by the server' |
99 ' due to malformed syntax.') | |
100 if code == 401: | 100 if code == 401: |
101 return _('Unauthorized access to resource') | 101 return _('Unauthorized access to resource') |
102 if code == 403: | 102 if code == 403: |
103 return _("You don't have permission to view this page") | 103 return _("You don't have permission to view this page") |
104 if code == 404: | 104 if code == 404: |
105 return _('The resource could not be found') | 105 return _('The resource could not be found') |
106 if code == 500: | 106 if code == 500: |
107 return _('The server encountered an unexpected condition which prevented it from fulfilling the request.') | 107 return _('The server encountered an unexpected condition' |
108 ' which prevented it from fulfilling the request.') |