annotate rhodecode/controllers/error.py @ 4147:1c8f818787b3 rhodecode-2.2.5-gpl

old style: show the full link box on summary page - no overlap or truncation
author Mads Kiilerich <madski@unity3d.com>
date Wed, 02 Jul 2014 19:03:23 -0400
parents ffd45b185016
children 7e5f8c12a3fc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
819
f579790a0ecd spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
1 # -*- coding: utf-8 -*-
1206
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
2 # This program is free software: you can redistribute it and/or modify
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
3 # it under the terms of the GNU General Public License as published by
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
4 # the Free Software Foundation, either version 3 of the License, or
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
5 # (at your option) any later version.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 986
diff changeset
6 #
819
f579790a0ecd spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
7 # 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
8 # 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
9 # 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
10 # GNU General Public License for more details.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 986
diff changeset
11 #
819
f579790a0ecd spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
12 # You should have received a copy of the GNU General Public License
1206
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
14 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
15 rhodecode.controllers.error
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
17
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
18 RhodeCode error controller
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
19
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
20 :created_on: Dec 8, 2010
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
21 :author: marcink
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
22 :copyright: (c) 2013 RhodeCode GmbH.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
23 :license: GPLv3, see LICENSE for more details.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
24 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
25
819
f579790a0ecd spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
26 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
27 import cgi
819
f579790a0ecd spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
28 import logging
14
923f0e6ab010 change error controller,
Marcin Kuzminski
parents: 0
diff changeset
29 import paste.fileapp
819
f579790a0ecd spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
30
1212
50e41777675d pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
31 from pylons import tmpl_context as c, request, config, url
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
32 from pylons.i18n.translation import _
819
f579790a0ecd spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
33 from pylons.middleware import media_path
f579790a0ecd spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
34
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 354
diff changeset
35 from rhodecode.lib.base import BaseController, render
819
f579790a0ecd spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
36
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
37 log = logging.getLogger(__name__)
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
38
1212
50e41777675d pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
39
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
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
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
42
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
43 The ErrorDocuments middleware forwards to ErrorController when error
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
44 related status codes are returned from the application.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
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
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
47 ErrorDocuments middleware in your config/middleware.py file.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
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):
1212
50e41777675d pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
51 #disable all base actions since we don't need them here
50e41777675d pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
52 pass
819
f579790a0ecd spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
53
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
54 def document(self):
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
55 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
56 c.rhodecode_name = config.get('rhodecode_title')
819
f579790a0ecd spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
57
1976
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
58 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
59
9f6300b96380 Updated error handling, from mercurial to pylons. + added tempalte for 404
Marcin Kuzminski <marcin@python-blog.com>
parents: 14
diff changeset
60 e = request.environ
1212
50e41777675d pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
61 c.serv_p = r'%(protocol)s://%(host)s/' \
50e41777675d pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
62 % {'protocol': e.get('wsgi.url_scheme'),
50e41777675d pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
63 'host': e.get('HTTP_HOST'), }
819
f579790a0ecd spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
64
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
65 c.error_message = cgi.escape(request.GET.get('code', str(resp.status)))
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
66 c.error_explanation = self.get_error_explanation(resp.status_int)
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
67
1212
50e41777675d pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
68 # redirect to when error with given seconds
14
923f0e6ab010 change error controller,
Marcin Kuzminski
parents: 0
diff changeset
69 c.redirect_time = 0
1212
50e41777675d pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
70 c.redirect_module = _('Home page')
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
71 c.url_redirect = "/"
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
72
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
73 return render('/errors/error_document.html')
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
74
14
923f0e6ab010 change error controller,
Marcin Kuzminski
parents: 0
diff changeset
75 def img(self, id):
923f0e6ab010 change error controller,
Marcin Kuzminski
parents: 0
diff changeset
76 """Serve Pylons' stock images"""
923f0e6ab010 change error controller,
Marcin Kuzminski
parents: 0
diff changeset
77 return self._serve_file(os.path.join(media_path, 'img', id))
923f0e6ab010 change error controller,
Marcin Kuzminski
parents: 0
diff changeset
78
923f0e6ab010 change error controller,
Marcin Kuzminski
parents: 0
diff changeset
79 def style(self, id):
923f0e6ab010 change error controller,
Marcin Kuzminski
parents: 0
diff changeset
80 """Serve Pylons' stock stylesheets"""
923f0e6ab010 change error controller,
Marcin Kuzminski
parents: 0
diff changeset
81 return self._serve_file(os.path.join(media_path, 'style', id))
923f0e6ab010 change error controller,
Marcin Kuzminski
parents: 0
diff changeset
82
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
83 def _serve_file(self, path):
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
84 """Call Paste's FileApp (a WSGI application) to serve the file
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
85 at the specified path
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
86 """
14
923f0e6ab010 change error controller,
Marcin Kuzminski
parents: 0
diff changeset
87 fapp = paste.fileapp.FileApp(path)
923f0e6ab010 change error controller,
Marcin Kuzminski
parents: 0
diff changeset
88 return fapp(request.environ, self.start_response)
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
89
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
90 def get_error_explanation(self, code):
3886
a1696507b3ad use consisten double quote docstring formatting
Marcin Kuzminski <marcin@python-works.com>
parents: 3631
diff changeset
91 """ get the error explanations of int codes
a1696507b3ad use consisten double quote docstring formatting
Marcin Kuzminski <marcin@python-works.com>
parents: 3631
diff changeset
92 [400, 401, 403, 404, 500]"""
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
93 try:
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
94 code = int(code)
3631
10b4e34841a4 Don't catch all exceptions
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
95 except Exception:
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
96 code = 500
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
97
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
98 if code == 400:
1212
50e41777675d pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
99 return _('The request could not be understood by the server'
50e41777675d pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
100 ' due to malformed syntax.')
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
101 if code == 401:
819
f579790a0ecd spelling fixes for error controller
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
102 return _('Unauthorized access to resource')
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
103 if code == 403:
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
104 return _("You don't have permission to view this page")
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
105 if code == 404:
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
106 return _('The resource could not be found')
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
107 if code == 500:
1212
50e41777675d pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
108 return _('The server encountered an unexpected condition'
50e41777675d pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
109 ' which prevented it from fulfilling the request.')