##// END OF EJS Templates
cleanup: remove accidental additions
dan -
r188:e9bff1bb default
parent child Browse files
Show More
@@ -1,88 +1,86 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2010-2016 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21
22 22 import logging
23 23 import pylons
24 24 import rhodecode
25 25
26 26 from pylons.i18n.translation import _get_translator
27 27 from pylons.util import ContextObj
28 28 from routes.util import URLGenerator
29 from pyramid.httpexceptions import HTTPInternalServerError, HTTPError, HTTPServiceUnavailable
30 29
31 30 from rhodecode.lib.base import attach_context_attributes, get_auth_user
32 31 from rhodecode.model import meta
33 32
34 33 log = logging.getLogger(__name__)
35 34
36 35
37 36 def pylons_compatibility_tween_factory(handler, registry):
38 37 def pylons_compatibility_tween(request):
39 38 """
40 39 While migrating from pylons to pyramid we need to call some pylons code
41 40 from pyramid. For example while rendering an old template that uses the
42 41 'c' or 'h' objects. This tween sets up the needed pylons globals.
43 42 """
44 43 try:
45 44 config = rhodecode.CONFIG
46 45 environ = request.environ
47 46 session = request.session
48 47 session_key = (config['pylons.environ_config']
49 48 .get('session', 'beaker.session'))
50 49
51 50 # Setup pylons globals.
52 51 pylons.config._push_object(config)
53 52 pylons.request._push_object(request)
54 53 pylons.session._push_object(session)
55 54 environ[session_key] = session
56 55 pylons.url._push_object(URLGenerator(config['routes.map'],
57 56 environ))
58 57
59 58 # TODO: Maybe we should use the language from pyramid.
60 59 translator = _get_translator(config.get('lang'))
61 60 pylons.translator._push_object(translator)
62 61
63 62 # Get the rhodecode auth user object and make it available.
64 63 auth_user = get_auth_user(environ)
65 64 request.user = auth_user
66 65 environ['rc_auth_user'] = auth_user
67 66
68 67 # Setup the pylons context object ('c')
69 68 context = ContextObj()
70 69 context.rhodecode_user = auth_user
71 70 attach_context_attributes(context)
72 71 pylons.tmpl_context._push_object(context)
73 response = handler(request)
74 return response
72 return handler(request)
75 73 finally:
76 74 # Dispose current database session and rollback uncommitted
77 75 # transactions.
78 76 meta.Session.remove()
79 77
80 78 return pylons_compatibility_tween
81 79
82 80
83 81 def includeme(config):
84 82 config.add_subscriber('rhodecode.subscribers.add_renderer_globals',
85 83 'pyramid.events.BeforeRender')
86 84 config.add_subscriber('rhodecode.subscribers.add_localizer',
87 85 'pyramid.events.NewRequest')
88 86 config.add_tween('rhodecode.tweens.pylons_compatibility_tween_factory')
General Comments 0
You need to be logged in to leave comments. Login now