##// END OF EJS Templates
admin: Register and retrieve navigation registry from pyramids registry.
Martin Bornhold -
r297:c84fdf50 default
parent child Browse files
Show More
@@ -19,10 +19,18 b''
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21
22 from rhodecode.admin.navigation import NavigationRegistry
22 23 from rhodecode.config.routing import ADMIN_PREFIX
24 from rhodecode.lib.utils2 import str2bool
23 25
24 26
25 27 def includeme(config):
28 settings = config.get_settings()
29
30 # Create admin navigation registry and add it to the pyramid registry.
31 labs_active = str2bool(settings.get('labs_settings_active', False))
32 navigation_registry = NavigationRegistry(labs_active=labs_active)
33 config.registry.registerUtility(navigation_registry)
26 34
27 35 config.add_route(
28 36 name='admin_settings_open_source',
@@ -21,13 +21,12 b''
21 21
22 22 import logging
23 23 import collections
24
24 25 from pylons import url
25 26 from pylons.i18n.translation import lazy_ugettext
26 27 from zope.interface import implementer
27 28
28 import rhodecode
29 29 from rhodecode.admin.interfaces import IAdminNavigationRegistry
30 from rhodecode.lib.utils2 import str2bool
31 30
32 31
33 32 log = logging.getLogger(__name__)
@@ -83,17 +82,16 b' class NavigationRegistry(object):'
83 82 # 'admin_settings_supervisor'),
84 83 ]
85 84
86 def __init__(self):
85 _labs_entry = NavEntry('labs', lazy_ugettext('Labs'),
86 'admin_settings_labs')
87
88 def __init__(self, labs_active=False):
87 89 self._registered_entries = collections.OrderedDict([
88 90 (item.key, item) for item in self.__class__._base_entries
89 91 ])
90 92
91 # Add the labs entry when it's activated.
92 labs_active = str2bool(
93 rhodecode.CONFIG.get('labs_settings_active', 'false'))
94 93 if labs_active:
95 self.add_entry(
96 NavEntry('labs', lazy_ugettext('Labs'), 'admin_settings_labs'))
94 self.add_entry(self._labs_entry)
97 95
98 96 def add_entry(self, entry):
99 97 self._registered_entries[entry.key] = entry
@@ -103,4 +101,18 b' class NavigationRegistry(object):'
103 101 for i in self._registered_entries.values()]
104 102 return navlist
105 103
106 navigation = NavigationRegistry()
104
105 def navigation_registry(request):
106 """
107 Helper that returns the admin navigation registry.
108 """
109 pyramid_registry = request.registry
110 nav_registry = pyramid_registry.queryUtility(IAdminNavigationRegistry)
111 return nav_registry
112
113
114 def navigation_list(request):
115 """
116 Helper that returns the admin navigation as list of NavListEntry objects.
117 """
118 return navigation_registry(request).get_navlist(request)
@@ -24,10 +24,11 b' import logging'
24 24 from pylons import tmpl_context as c
25 25 from pyramid.view import view_config
26 26
27 from rhodecode.controllers.admin.settings import navigation
28 27 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
29 28 from rhodecode.lib.utils import read_opensource_licenses
30 29
30 from .navigation import navigation_list
31
31 32
32 33 log = logging.getLogger(__name__)
33 34
@@ -47,7 +48,7 b' class AdminSettingsView(object):'
47 48 renderer='rhodecode:templates/admin/settings/settings.html')
48 49 def open_source_licenses(self):
49 50 c.active = 'open_source'
50 c.navlist = navigation.get_navlist(self.request)
51 c.navlist = navigation_list(self.request)
51 52 c.opensource_licenses = collections.OrderedDict(
52 53 sorted(read_opensource_licenses().items(), key=lambda t: t[0]))
53 54
@@ -37,7 +37,7 b' from pylons.i18n.translation import _, l'
37 37 from webob.exc import HTTPBadRequest
38 38
39 39 import rhodecode
40 from rhodecode.admin.navigation import navigation
40 from rhodecode.admin.navigation import navigation_list
41 41 from rhodecode.lib import auth
42 42 from rhodecode.lib import helpers as h
43 43 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
@@ -80,7 +80,7 b' class SettingsController(BaseController)'
80 80 super(SettingsController, self).__before__()
81 81 c.labs_active = str2bool(
82 82 rhodecode.CONFIG.get('labs_settings_active', 'false'))
83 c.navlist = navigation.get_navlist(request)
83 c.navlist = navigation_list(request)
84 84
85 85 def _get_hg_ui_settings(self):
86 86 ret = RhodeCodeUi.query().all()
General Comments 0
You need to be logged in to leave comments. Login now