Mercurial > kallithea
annotate rhodecode/controllers/error.py @ 723:bf26b46e82d6 beta
some tests update
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 18 Nov 2010 23:11:51 +0100 |
parents | 1e757ac98988 |
children | f579790a0ecd |
rev | line source |
---|---|
0 | 1 import logging |
125
2811259dc12d
Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents:
101
diff
changeset
|
2 import cgi |
2811259dc12d
Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents:
101
diff
changeset
|
3 import os |
14 | 4 import paste.fileapp |
87
9f6300b96380
Updated error handling, from mercurial to pylons. + added tempalte for 404
Marcin Kuzminski <marcin@python-blog.com>
parents:
14
diff
changeset
|
5 from pylons import tmpl_context as c, app_globals as g, request, config |
0 | 6 from pylons.controllers.util import forward |
7 from pylons.i18n.translation import _ | |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
354
diff
changeset
|
8 from rhodecode.lib.base import BaseController, render |
125
2811259dc12d
Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents:
101
diff
changeset
|
9 from pylons.middleware import media_path |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
354
diff
changeset
|
10 from rhodecode.lib.utils import check_repo |
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
354
diff
changeset
|
11 import rhodecode.lib.helpers as h |
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
354
diff
changeset
|
12 from rhodecode import __version__ |
215
70f645fa97cc
Moved repo creation to admin/repos, as part of crud controller. Now repo creation is based on a form, which can be auto filled with data from 404 page. Fixed the error controller to properly give the repo name.
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
13 log = logging.getLogger(__name__) |
0 | 14 |
15 class ErrorController(BaseController): | |
16 """ | |
17 Generates error documents as and when they are required. | |
18 | |
19 The ErrorDocuments middleware forwards to ErrorController when error | |
20 related status codes are returned from the application. | |
21 | |
22 This behaviour can be altered by changing the parameters to the | |
23 ErrorDocuments middleware in your config/middleware.py file. | |
24 """ | |
311
9a70fe918a81
fixed error controller __before__ behavior,
Marcin Kuzminski <marcin@python-works.com>
parents:
260
diff
changeset
|
25 def __before__(self): |
9a70fe918a81
fixed error controller __before__ behavior,
Marcin Kuzminski <marcin@python-works.com>
parents:
260
diff
changeset
|
26 pass#disable all base actions since we don't need them here |
87
9f6300b96380
Updated error handling, from mercurial to pylons. + added tempalte for 404
Marcin Kuzminski <marcin@python-blog.com>
parents:
14
diff
changeset
|
27 |
0 | 28 def document(self): |
29 resp = request.environ.get('pylons.original_response') | |
215
70f645fa97cc
Moved repo creation to admin/repos, as part of crud controller. Now repo creation is based on a form, which can be auto filled with data from 404 page. Fixed the error controller to properly give the repo name.
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
30 |
311
9a70fe918a81
fixed error controller __before__ behavior,
Marcin Kuzminski <marcin@python-works.com>
parents:
260
diff
changeset
|
31 log.debug('### %s ###', resp.status) |
87
9f6300b96380
Updated error handling, from mercurial to pylons. + added tempalte for 404
Marcin Kuzminski <marcin@python-blog.com>
parents:
14
diff
changeset
|
32 |
9f6300b96380
Updated error handling, from mercurial to pylons. + added tempalte for 404
Marcin Kuzminski <marcin@python-blog.com>
parents:
14
diff
changeset
|
33 e = request.environ |
9f6300b96380
Updated error handling, from mercurial to pylons. + added tempalte for 404
Marcin Kuzminski <marcin@python-blog.com>
parents:
14
diff
changeset
|
34 c.serv_p = r'%(protocol)s://%(host)s/' % { |
9f6300b96380
Updated error handling, from mercurial to pylons. + added tempalte for 404
Marcin Kuzminski <marcin@python-blog.com>
parents:
14
diff
changeset
|
35 'protocol': e.get('wsgi.url_scheme'), |
9f6300b96380
Updated error handling, from mercurial to pylons. + added tempalte for 404
Marcin Kuzminski <marcin@python-blog.com>
parents:
14
diff
changeset
|
36 'host':e.get('HTTP_HOST'), |
9f6300b96380
Updated error handling, from mercurial to pylons. + added tempalte for 404
Marcin Kuzminski <marcin@python-blog.com>
parents:
14
diff
changeset
|
37 } |
125
2811259dc12d
Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents:
101
diff
changeset
|
38 |
87
9f6300b96380
Updated error handling, from mercurial to pylons. + added tempalte for 404
Marcin Kuzminski <marcin@python-blog.com>
parents:
14
diff
changeset
|
39 |
0 | 40 c.error_message = cgi.escape(request.GET.get('code', str(resp.status))) |
41 c.error_explanation = self.get_error_explanation(resp.status_int) | |
42 | |
43 #redirect to when error with given seconds | |
14 | 44 c.redirect_time = 0 |
0 | 45 c.redirect_module = _('Home page')# name to what your going to be redirected |
46 c.url_redirect = "/" | |
47 | |
48 return render('/errors/error_document.html') | |
49 | |
14 | 50 |
51 def img(self, id): | |
52 """Serve Pylons' stock images""" | |
53 return self._serve_file(os.path.join(media_path, 'img', id)) | |
54 | |
55 def style(self, id): | |
56 """Serve Pylons' stock stylesheets""" | |
57 return self._serve_file(os.path.join(media_path, 'style', id)) | |
58 | |
0 | 59 def _serve_file(self, path): |
60 """Call Paste's FileApp (a WSGI application) to serve the file | |
61 at the specified path | |
62 """ | |
14 | 63 fapp = paste.fileapp.FileApp(path) |
64 return fapp(request.environ, self.start_response) | |
0 | 65 |
66 def get_error_explanation(self, code): | |
67 ''' get the error explanations of int codes | |
68 [400, 401, 403, 404, 500]''' | |
69 try: | |
70 code = int(code) | |
71 except: | |
72 code = 500 | |
73 | |
74 if code == 400: | |
75 return _('The request could not be understood by the server due to malformed syntax.') | |
76 if code == 401: | |
77 return _('Unathorized access to resource') | |
78 if code == 403: | |
79 return _("You don't have permission to view this page") | |
80 if code == 404: | |
81 return _('The resource could not be found') | |
82 if code == 500: | |
83 return _('The server encountered an unexpected condition which prevented it from fulfilling the request.') | |
84 | |
85 |