diff --git a/rhodecode/admin/__init__.py b/rhodecode/admin/__init__.py --- a/rhodecode/admin/__init__.py +++ b/rhodecode/admin/__init__.py @@ -19,10 +19,18 @@ # and proprietary license terms, please see https://rhodecode.com/licenses/ +from rhodecode.admin.navigation import NavigationRegistry from rhodecode.config.routing import ADMIN_PREFIX +from rhodecode.lib.utils2 import str2bool def includeme(config): + settings = config.get_settings() + + # Create admin navigation registry and add it to the pyramid registry. + labs_active = str2bool(settings.get('labs_settings_active', False)) + navigation_registry = NavigationRegistry(labs_active=labs_active) + config.registry.registerUtility(navigation_registry) config.add_route( name='admin_settings_open_source', diff --git a/rhodecode/admin/navigation.py b/rhodecode/admin/navigation.py --- a/rhodecode/admin/navigation.py +++ b/rhodecode/admin/navigation.py @@ -21,13 +21,12 @@ import logging import collections + from pylons import url from pylons.i18n.translation import lazy_ugettext from zope.interface import implementer -import rhodecode from rhodecode.admin.interfaces import IAdminNavigationRegistry -from rhodecode.lib.utils2 import str2bool log = logging.getLogger(__name__) @@ -83,17 +82,16 @@ class NavigationRegistry(object): # 'admin_settings_supervisor'), ] - def __init__(self): + _labs_entry = NavEntry('labs', lazy_ugettext('Labs'), + 'admin_settings_labs') + + def __init__(self, labs_active=False): self._registered_entries = collections.OrderedDict([ (item.key, item) for item in self.__class__._base_entries ]) - # Add the labs entry when it's activated. - labs_active = str2bool( - rhodecode.CONFIG.get('labs_settings_active', 'false')) if labs_active: - self.add_entry( - NavEntry('labs', lazy_ugettext('Labs'), 'admin_settings_labs')) + self.add_entry(self._labs_entry) def add_entry(self, entry): self._registered_entries[entry.key] = entry @@ -103,4 +101,18 @@ class NavigationRegistry(object): for i in self._registered_entries.values()] return navlist -navigation = NavigationRegistry() + +def navigation_registry(request): + """ + Helper that returns the admin navigation registry. + """ + pyramid_registry = request.registry + nav_registry = pyramid_registry.queryUtility(IAdminNavigationRegistry) + return nav_registry + + +def navigation_list(request): + """ + Helper that returns the admin navigation as list of NavListEntry objects. + """ + return navigation_registry(request).get_navlist(request) diff --git a/rhodecode/admin/views.py b/rhodecode/admin/views.py --- a/rhodecode/admin/views.py +++ b/rhodecode/admin/views.py @@ -24,10 +24,11 @@ import logging from pylons import tmpl_context as c from pyramid.view import view_config -from rhodecode.controllers.admin.settings import navigation from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator from rhodecode.lib.utils import read_opensource_licenses +from .navigation import navigation_list + log = logging.getLogger(__name__) @@ -47,7 +48,7 @@ class AdminSettingsView(object): renderer='rhodecode:templates/admin/settings/settings.html') def open_source_licenses(self): c.active = 'open_source' - c.navlist = navigation.get_navlist(self.request) + c.navlist = navigation_list(self.request) c.opensource_licenses = collections.OrderedDict( sorted(read_opensource_licenses().items(), key=lambda t: t[0])) diff --git a/rhodecode/controllers/admin/settings.py b/rhodecode/controllers/admin/settings.py --- a/rhodecode/controllers/admin/settings.py +++ b/rhodecode/controllers/admin/settings.py @@ -37,7 +37,7 @@ from pylons.i18n.translation import _, l from webob.exc import HTTPBadRequest import rhodecode -from rhodecode.admin.navigation import navigation +from rhodecode.admin.navigation import navigation_list from rhodecode.lib import auth from rhodecode.lib import helpers as h from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator @@ -80,7 +80,7 @@ class SettingsController(BaseController) super(SettingsController, self).__before__() c.labs_active = str2bool( rhodecode.CONFIG.get('labs_settings_active', 'false')) - c.navlist = navigation.get_navlist(request) + c.navlist = navigation_list(request) def _get_hg_ui_settings(self): ret = RhodeCodeUi.query().all()