##// END OF EJS Templates
admin: Add helper to get the registry from requests.
Martin Bornhold -
r298:d27ab834 default
parent child Browse files
Show More
@@ -27,6 +27,7 b' from pylons.i18n.translation import lazy'
27 27 from zope.interface import implementer
28 28
29 29 from rhodecode.admin.interfaces import IAdminNavigationRegistry
30 from rhodecode.lib.utils import get_registry
30 31
31 32
32 33 log = logging.getLogger(__name__)
@@ -35,6 +36,15 b" NavListEntry = collections.namedtuple('N"
35 36
36 37
37 38 class NavEntry(object):
39 """
40 Represents an entry in the admin navigation.
41
42 :param key: Unique identifier used to store reference in an OrderedDict.
43 :param name: Display name, usually a translation string.
44 :param view_name: Name of the view, used generate the URL.
45 :param pyramid: Indicator to use pyramid for URL generation. This should
46 be removed as soon as we are fully migrated to pyramid.
47 """
38 48
39 49 def __init__(self, key, name, view_name, pyramid=False):
40 50 self.key = key
@@ -106,7 +116,7 b' def navigation_registry(request):'
106 116 """
107 117 Helper that returns the admin navigation registry.
108 118 """
109 pyramid_registry = request.registry
119 pyramid_registry = get_registry(request)
110 120 nav_registry = pyramid_registry.queryUtility(IAdminNavigationRegistry)
111 121 return nav_registry
112 122
@@ -33,14 +33,14 b' import tempfile'
33 33 import traceback
34 34 import tarfile
35 35 import warnings
36 from os.path import abspath
37 from os.path import dirname as dn, join as jn
36 from os.path import join as jn
38 37
39 38 import paste
40 39 import pkg_resources
41 40 from paste.script.command import Command, BadCommand
42 41 from webhelpers.text import collapse, remove_formatting, strip_tags
43 42 from mako import exceptions
43 from pyramid.threadlocal import get_current_registry
44 44
45 45 from rhodecode.lib.fakemod import create_module
46 46 from rhodecode.lib.vcs.backends.base import Config
@@ -975,3 +975,16 b' def read_opensource_licenses():'
975 975 _license_cache = json.loads(licenses)
976 976
977 977 return _license_cache
978
979
980 def get_registry(request):
981 """
982 Utility to get the pyramid registry from a request. During migration to
983 pyramid we sometimes want to use the pyramid registry from pylons context.
984 Therefore this utility returns `request.registry` for pyramid requests and
985 uses `get_current_registry()` for pylons requests.
986 """
987 try:
988 return request.registry
989 except AttributeError:
990 return get_current_registry()
General Comments 0
You need to be logged in to leave comments. Login now