Mercurial > kallithea
annotate rhodecode/controllers/error.py @ 1173:f2b5279a5c77 beta
Added tag v1.1.7 for changeset 2ab211e0aecd
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 23 Mar 2011 20:56:05 +0100 |
parents | 5256b255269a |
children | 6832ef664673 |
rev | line source |
---|---|
819
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
1 # -*- coding: utf-8 -*- |
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
2 """ |
860
5f7731e3ab4d
fixed spelling mistakes, and some minor docs bugs
Marcin Kuzminski <marcin@python-works.com>
parents:
819
diff
changeset
|
3 rhodecode.controllers.error |
5f7731e3ab4d
fixed spelling mistakes, and some minor docs bugs
Marcin Kuzminski <marcin@python-works.com>
parents:
819
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
819
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
5 |
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
6 RhodeCode error controller |
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
7 |
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
8 :created_on: Dec 8, 2010 |
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
9 :author: marcink |
902
07a6e8c65526
fixed copyright year to 2011
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com> |
819
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
11 :license: GPLv3, see COPYING for more details. |
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
12 """ |
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
13 # This program is free software; you can redistribute it and/or |
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
14 # modify it under the terms of the GNU General Public License |
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
15 # as published by the Free Software Foundation; version 2 |
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
16 # of the License or (at your opinion) any later version of the license. |
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
17 # |
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
18 # This program is distributed in the hope that it will be useful, |
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
21 # GNU General Public License for more details. |
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
22 # |
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
23 # You should have received a copy of the GNU General Public License |
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
24 # along with this program; if not, write to the Free Software |
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
26 # MA 02110-1301, USA. |
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
27 import os |
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
|
28 import cgi |
819
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
29 import logging |
14 | 30 import paste.fileapp |
819
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
31 |
986
5256b255269a
removed obsolete css from 404 page, and implemented rhodecode title app in the error page
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
32 from pylons import tmpl_context as c, request, config |
0 | 33 from pylons.i18n.translation import _ |
819
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
34 from pylons.middleware import media_path |
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
35 |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
354
diff
changeset
|
36 from rhodecode.lib.base import BaseController, render |
819
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
37 |
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
|
38 log = logging.getLogger(__name__) |
0 | 39 |
40 class ErrorController(BaseController): | |
819
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
41 """Generates error documents as and when they are required. |
0 | 42 |
43 The ErrorDocuments middleware forwards to ErrorController when error | |
44 related status codes are returned from the application. | |
45 | |
819
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
46 This behavior can be altered by changing the parameters to the |
0 | 47 ErrorDocuments middleware in your config/middleware.py file. |
48 """ | |
819
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
49 |
311
9a70fe918a81
fixed error controller __before__ behavior,
Marcin Kuzminski <marcin@python-works.com>
parents:
260
diff
changeset
|
50 def __before__(self): |
9a70fe918a81
fixed error controller __before__ behavior,
Marcin Kuzminski <marcin@python-works.com>
parents:
260
diff
changeset
|
51 pass#disable all base actions since we don't need them here |
819
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
52 |
0 | 53 def document(self): |
54 resp = request.environ.get('pylons.original_response') | |
986
5256b255269a
removed obsolete css from 404 page, and implemented rhodecode title app in the error page
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
55 c.rhodecode_name = config.get('rhodecode_title') |
819
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
56 |
311
9a70fe918a81
fixed error controller __before__ behavior,
Marcin Kuzminski <marcin@python-works.com>
parents:
260
diff
changeset
|
57 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
|
58 |
9f6300b96380
Updated error handling, from mercurial to pylons. + added tempalte for 404
Marcin Kuzminski <marcin@python-blog.com>
parents:
14
diff
changeset
|
59 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
|
60 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
|
61 '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
|
62 '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
|
63 } |
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
|
64 |
819
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
65 |
0 | 66 c.error_message = cgi.escape(request.GET.get('code', str(resp.status))) |
67 c.error_explanation = self.get_error_explanation(resp.status_int) | |
68 | |
69 #redirect to when error with given seconds | |
14 | 70 c.redirect_time = 0 |
0 | 71 c.redirect_module = _('Home page')# name to what your going to be redirected |
72 c.url_redirect = "/" | |
73 | |
74 return render('/errors/error_document.html') | |
75 | |
14 | 76 |
77 def img(self, id): | |
78 """Serve Pylons' stock images""" | |
79 return self._serve_file(os.path.join(media_path, 'img', id)) | |
80 | |
81 def style(self, id): | |
82 """Serve Pylons' stock stylesheets""" | |
83 return self._serve_file(os.path.join(media_path, 'style', id)) | |
84 | |
0 | 85 def _serve_file(self, path): |
86 """Call Paste's FileApp (a WSGI application) to serve the file | |
87 at the specified path | |
88 """ | |
14 | 89 fapp = paste.fileapp.FileApp(path) |
90 return fapp(request.environ, self.start_response) | |
0 | 91 |
92 def get_error_explanation(self, code): | |
93 ''' get the error explanations of int codes | |
94 [400, 401, 403, 404, 500]''' | |
95 try: | |
96 code = int(code) | |
97 except: | |
98 code = 500 | |
99 | |
100 if code == 400: | |
101 return _('The request could not be understood by the server due to malformed syntax.') | |
102 if code == 401: | |
819
f579790a0ecd
spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
103 return _('Unauthorized access to resource') |
0 | 104 if code == 403: |
105 return _("You don't have permission to view this page") | |
106 if code == 404: | |
107 return _('The resource could not be found') | |
108 if code == 500: | |
109 return _('The server encountered an unexpected condition which prevented it from fulfilling the request.') | |
110 | |
111 |