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