Show More
@@ -1,128 +1,124 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2016-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 collections |
|
24 | 24 | |
|
25 | 25 | from pylons import url |
|
26 | from pylons.i18n.translation import lazy_ugettext | |
|
27 | 26 | from zope.interface import implementer |
|
28 | 27 | |
|
29 | 28 | from rhodecode.admin.interfaces import IAdminNavigationRegistry |
|
30 | 29 | from rhodecode.lib.utils import get_registry |
|
30 | from rhodecode.translation import _ | |
|
31 | 31 | |
|
32 | 32 | |
|
33 | 33 | log = logging.getLogger(__name__) |
|
34 | 34 | |
|
35 | 35 | NavListEntry = collections.namedtuple('NavListEntry', ['key', 'name', 'url']) |
|
36 | 36 | |
|
37 | 37 | |
|
38 | 38 | class NavEntry(object): |
|
39 | 39 | """ |
|
40 | 40 | Represents an entry in the admin navigation. |
|
41 | 41 | |
|
42 | 42 | :param key: Unique identifier used to store reference in an OrderedDict. |
|
43 | 43 | :param name: Display name, usually a translation string. |
|
44 | 44 | :param view_name: Name of the view, used generate the URL. |
|
45 | 45 | :param pyramid: Indicator to use pyramid for URL generation. This should |
|
46 | 46 | be removed as soon as we are fully migrated to pyramid. |
|
47 | 47 | """ |
|
48 | 48 | |
|
49 | 49 | def __init__(self, key, name, view_name, pyramid=False): |
|
50 | 50 | self.key = key |
|
51 | 51 | self.name = name |
|
52 | 52 | self.view_name = view_name |
|
53 | 53 | self.pyramid = pyramid |
|
54 | 54 | |
|
55 | 55 | def generate_url(self, request): |
|
56 | 56 | if self.pyramid: |
|
57 | 57 | if hasattr(request, 'route_path'): |
|
58 | 58 | return request.route_path(self.view_name) |
|
59 | 59 | else: |
|
60 | 60 | # TODO: johbo: Remove this after migrating to pyramid. |
|
61 | 61 | # We need the pyramid request here to generate URLs to pyramid |
|
62 | 62 | # views from within pylons views. |
|
63 | 63 | from pyramid.threadlocal import get_current_request |
|
64 | 64 | pyramid_request = get_current_request() |
|
65 | 65 | return pyramid_request.route_path(self.view_name) |
|
66 | 66 | else: |
|
67 | 67 | return url(self.view_name) |
|
68 | 68 | |
|
69 | 69 | |
|
70 | 70 | @implementer(IAdminNavigationRegistry) |
|
71 | 71 | class NavigationRegistry(object): |
|
72 | 72 | |
|
73 | 73 | _base_entries = [ |
|
74 |
NavEntry('global', |
|
|
75 |
NavEntry('vcs', |
|
|
76 |
NavEntry('visual', |
|
|
77 |
NavEntry('mapping', |
|
|
78 | 'admin_settings_mapping'), | |
|
79 | NavEntry('issuetracker', lazy_ugettext('Issue Tracker'), | |
|
74 | NavEntry('global', _('Global'), 'admin_settings_global'), | |
|
75 | NavEntry('vcs', _('VCS'), 'admin_settings_vcs'), | |
|
76 | NavEntry('visual', _('Visual'), 'admin_settings_visual'), | |
|
77 | NavEntry('mapping', _('Remap and Rescan'), 'admin_settings_mapping'), | |
|
78 | NavEntry('issuetracker', _('Issue Tracker'), | |
|
80 | 79 | 'admin_settings_issuetracker'), |
|
81 |
NavEntry('email', |
|
|
82 |
NavEntry('hooks', |
|
|
83 |
NavEntry('search', |
|
|
84 | 'admin_settings_search'), | |
|
85 | NavEntry('system', lazy_ugettext('System Info'), | |
|
86 | 'admin_settings_system'), | |
|
87 | NavEntry('open_source', lazy_ugettext('Open Source Licenses'), | |
|
80 | NavEntry('email', _('Email'), 'admin_settings_email'), | |
|
81 | NavEntry('hooks', _('Hooks'), 'admin_settings_hooks'), | |
|
82 | NavEntry('search', _('Full Text Search'), 'admin_settings_search'), | |
|
83 | NavEntry('system', _('System Info'), 'admin_settings_system'), | |
|
84 | NavEntry('open_source', _('Open Source Licenses'), | |
|
88 | 85 | 'admin_settings_open_source', pyramid=True), |
|
89 | 86 | # TODO: marcink: we disable supervisor now until the supervisor stats |
|
90 | 87 | # page is fixed in the nix configuration |
|
91 |
# NavEntry('supervisor', |
|
|
92 | # 'admin_settings_supervisor'), | |
|
88 | # NavEntry('supervisor', _('Supervisor'), 'admin_settings_supervisor'), | |
|
93 | 89 | ] |
|
94 | 90 | |
|
95 |
_labs_entry = NavEntry('labs', |
|
|
91 | _labs_entry = NavEntry('labs', _('Labs'), | |
|
96 | 92 | 'admin_settings_labs') |
|
97 | 93 | |
|
98 | 94 | def __init__(self, labs_active=False): |
|
99 | 95 | self._registered_entries = collections.OrderedDict([ |
|
100 | 96 | (item.key, item) for item in self.__class__._base_entries |
|
101 | 97 | ]) |
|
102 | 98 | |
|
103 | 99 | if labs_active: |
|
104 | 100 | self.add_entry(self._labs_entry) |
|
105 | 101 | |
|
106 | 102 | def add_entry(self, entry): |
|
107 | 103 | self._registered_entries[entry.key] = entry |
|
108 | 104 | |
|
109 | 105 | def get_navlist(self, request): |
|
110 | 106 | navlist = [NavListEntry(i.key, i.name, i.generate_url(request)) |
|
111 | 107 | for i in self._registered_entries.values()] |
|
112 | 108 | return navlist |
|
113 | 109 | |
|
114 | 110 | |
|
115 | 111 | def navigation_registry(request): |
|
116 | 112 | """ |
|
117 | 113 | Helper that returns the admin navigation registry. |
|
118 | 114 | """ |
|
119 | 115 | pyramid_registry = get_registry(request) |
|
120 | 116 | nav_registry = pyramid_registry.queryUtility(IAdminNavigationRegistry) |
|
121 | 117 | return nav_registry |
|
122 | 118 | |
|
123 | 119 | |
|
124 | 120 | def navigation_list(request): |
|
125 | 121 | """ |
|
126 | 122 | Helper that returns the admin navigation as list of NavListEntry objects. |
|
127 | 123 | """ |
|
128 | 124 | return navigation_registry(request).get_navlist(request) |
General Comments 0
You need to be logged in to leave comments.
Login now