##// END OF EJS Templates
i18n: translate properly navList and also support proper translation into other admin views.
marcink -
r1305:b418df09 default
parent child Browse files
Show More
@@ -1,133 +1,140 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2016-2017 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 26 from zope.interface import implementer
27 27
28 28 from rhodecode.admin.interfaces import IAdminNavigationRegistry
29 29 from rhodecode.lib.utils import get_registry
30 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 def get_localized_name(self, request):
70 if hasattr(request, 'translate'):
71 return request.translate(self.name)
72 else:
73 # TODO(marcink): Remove this after migrating to pyramid
74 from pyramid.threadlocal import get_current_request
75 pyramid_request = get_current_request()
76 return pyramid_request.translate(self.name)
77
69 78
70 79 @implementer(IAdminNavigationRegistry)
71 80 class NavigationRegistry(object):
72 81
73 82 _base_entries = [
74 83 NavEntry('global', _('Global'), 'admin_settings_global'),
75 84 NavEntry('vcs', _('VCS'), 'admin_settings_vcs'),
76 85 NavEntry('visual', _('Visual'), 'admin_settings_visual'),
77 86 NavEntry('mapping', _('Remap and Rescan'), 'admin_settings_mapping'),
78 87 NavEntry('issuetracker', _('Issue Tracker'),
79 88 'admin_settings_issuetracker'),
80 89 NavEntry('email', _('Email'), 'admin_settings_email'),
81 90 NavEntry('hooks', _('Hooks'), 'admin_settings_hooks'),
82 91 NavEntry('search', _('Full Text Search'), 'admin_settings_search'),
83 92
84
85 93 NavEntry('integrations', _('Integrations'),
86 94 'global_integrations_home', pyramid=True),
87 NavEntry('system', _('System Info'), 'admin_settings_system'),
88
89
90 NavEntry('session', _('User Sessions'),
95 NavEntry('system', _('System Info'),
96 'admin_settings_system', pyramid=True),
97 NavEntry('sessions', _('User Sessions'),
91 98 'admin_settings_sessions', pyramid=True),
92 99 NavEntry('open_source', _('Open Source Licenses'),
93 100 'admin_settings_open_source', pyramid=True),
94 101
95 102 # TODO: marcink: we disable supervisor now until the supervisor stats
96 103 # page is fixed in the nix configuration
97 104 # NavEntry('supervisor', _('Supervisor'), 'admin_settings_supervisor'),
98 105 ]
99 106
100 _labs_entry = NavEntry('labs', _('Labs'),
101 'admin_settings_labs')
107 _labs_entry = NavEntry('labs', _('Labs'), 'admin_settings_labs')
102 108
103 109 def __init__(self, labs_active=False):
104 110 self._registered_entries = collections.OrderedDict([
105 111 (item.key, item) for item in self.__class__._base_entries
106 112 ])
107 113
108 114 if labs_active:
109 115 self.add_entry(self._labs_entry)
110 116
111 117 def add_entry(self, entry):
112 118 self._registered_entries[entry.key] = entry
113 119
114 120 def get_navlist(self, request):
115 navlist = [NavListEntry(i.key, i.name, i.generate_url(request))
121 navlist = [NavListEntry(i.key, i.get_localized_name(request),
122 i.generate_url(request))
116 123 for i in self._registered_entries.values()]
117 124 return navlist
118 125
119 126
120 127 def navigation_registry(request):
121 128 """
122 129 Helper that returns the admin navigation registry.
123 130 """
124 131 pyramid_registry = get_registry(request)
125 132 nav_registry = pyramid_registry.queryUtility(IAdminNavigationRegistry)
126 133 return nav_registry
127 134
128 135
129 136 def navigation_list(request):
130 137 """
131 138 Helper that returns the admin navigation as list of NavListEntry objects.
132 139 """
133 140 return navigation_registry(request).get_navlist(request)
@@ -1,60 +1,60 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2016-2017 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 import logging
22 22
23 23 from pyramid.view import view_config
24 24
25 from rhodecode.translation import _
26 25 from rhodecode.svn_support.utils import generate_mod_dav_svn_config
27 26
28 27 from rhodecode.admin.views.base import AdminSettingsView
29 28 from rhodecode.lib.auth import (
30 29 LoginRequired, HasPermissionAllDecorator, CSRFRequired)
31 30
32 31 log = logging.getLogger(__name__)
33 32
34 33
35 34 class SvnConfigAdminSettingsView(AdminSettingsView):
36 35
37 36 @LoginRequired()
38 37 @CSRFRequired()
39 38 @HasPermissionAllDecorator('hg.admin')
40 39 @view_config(
41 40 route_name='admin_settings_vcs_svn_generate_cfg',
42 41 request_method='POST', renderer='json')
43 42 def vcs_svn_generate_config(self):
43 _ = self.request.translate
44 44 try:
45 45 generate_mod_dav_svn_config(self.request.registry)
46 46 msg = {
47 47 'message': _('Apache configuration for Subversion generated.'),
48 48 'level': 'success',
49 49 }
50 50 except Exception:
51 51 log.exception(
52 52 'Exception while generating the Apache '
53 53 'configuration for Subversion.')
54 54 msg = {
55 55 'message': _('Failed to generate the Apache configuration for Subversion.'),
56 56 'level': 'error',
57 57 }
58 58
59 59 data = {'message': msg}
60 60 return data
General Comments 0
You need to be logged in to leave comments. Login now