# HG changeset patch # User Marcin Kuzminski # Date 2017-07-13 08:57:57 # Node ID f0e0aac6440c5e84b2d6bbaefa723a2a2bfe8a1a # Parent 5b0f9bcba6ab6b1a7f6651b339abbd4e29d605ec pyramid: allows easier turning off the pylons components. diff --git a/rhodecode/apps/_base/__init__.py b/rhodecode/apps/_base/__init__.py --- a/rhodecode/apps/_base/__init__.py +++ b/rhodecode/apps/_base/__init__.py @@ -124,8 +124,12 @@ class BaseAppView(object): # TODO(marcink): remove once pyramid migration is finished from pylons import tmpl_context as c - for k, v in tmpl_args.items(): - setattr(c, k, v) + try: + for k, v in tmpl_args.items(): + setattr(c, k, v) + except TypeError: + log.exception('Failed to register pylons C') + pass def _get_template_context(self, tmpl_args): self._register_global_c(tmpl_args) diff --git a/rhodecode/config/middleware.py b/rhodecode/config/middleware.py --- a/rhodecode/config/middleware.py +++ b/rhodecode/config/middleware.py @@ -345,7 +345,7 @@ def includeme(config): config.add_notfound_view(make_not_found_view(config)) if not settings.get('debugtoolbar.enabled', False): - # if no toolbar, then any exception gets caught and rendered + # disabled debugtoolbar handle all exceptions via the error_handlers config.add_view(error_handler, context=Exception) config.add_view(error_handler, context=HTTPError) @@ -388,9 +388,13 @@ def wrap_app_in_wsgi_middlewares(pyramid # Add RoutesMiddleware to support the pylons compatibility tween during # migration to pyramid. - pyramid_app = SkippableRoutesMiddleware( - pyramid_app, config.registry._pylons_compat_config['routes.map'], - skip_prefixes=(STATIC_FILE_PREFIX, '/_debug_toolbar')) + + # TODO(marcink): remove after migration to pyramid + if hasattr(config.registry, '_pylons_compat_config'): + routes_map = config.registry._pylons_compat_config['routes.map'] + pyramid_app = SkippableRoutesMiddleware( + pyramid_app, routes_map, + skip_prefixes=(STATIC_FILE_PREFIX, '/_debug_toolbar')) pyramid_app, _ = wrap_in_appenlight_if_enabled(pyramid_app, settings) diff --git a/rhodecode/lib/helpers.py b/rhodecode/lib/helpers.py --- a/rhodecode/lib/helpers.py +++ b/rhodecode/lib/helpers.py @@ -48,7 +48,6 @@ from pygments.formatters.html import Htm from pygments import highlight as code_highlight from pygments.lexers import ( get_lexer_by_name, get_lexer_for_filename, get_lexer_for_mimetype) -from pylons import url as pylons_url from pylons.i18n.translation import _, ungettext from pyramid.threadlocal import get_current_request @@ -94,6 +93,7 @@ DEFAULT_USER_EMAIL = User.DEFAULT_USER_E def url(*args, **kw): + from pylons import url as pylons_url return pylons_url(*args, **kw) @@ -103,6 +103,7 @@ def pylons_url_current(*args, **kw): path so that it will also work from a pyramid only context. This should be removed once port to pyramid is complete. """ + from pylons import url as pylons_url if not args and not kw: request = get_current_request() return request.path diff --git a/rhodecode/subscribers.py b/rhodecode/subscribers.py --- a/rhodecode/subscribers.py +++ b/rhodecode/subscribers.py @@ -232,8 +232,10 @@ def write_js_routes_if_enabled(event): def get_routes(): # pylons routes - for route in rhodecode.CONFIG['routes.map'].jsroutes(): - yield route + # TODO(marcink): remove when pyramid migration is finished + if 'routes.map' in rhodecode.CONFIG: + for route in rhodecode.CONFIG['routes.map'].jsroutes(): + yield route # pyramid routes for route in mapper.get_routes():