Added "get_global_registry" function
authorThierry Florac <thierry.florac@onf.fr>
Fri, 10 Nov 2017 13:51:21 +0100
changeset 118 de78bbbc9f50
parent 117 c43465fd39a8
child 119 664b86f16a91
Added "get_global_registry" function
src/pyams_utils/registry.py
--- a/src/pyams_utils/registry.py	Fri Nov 10 13:50:06 2017 +0100
+++ b/src/pyams_utils/registry.py	Fri Nov 10 13:51:21 2017 +0100
@@ -38,8 +38,9 @@
 
 # import packages
 from pyramid.events import subscriber
-from pyramid.threadlocal import manager
+from pyramid.threadlocal import manager, get_current_registry
 from ZODB.POSException import POSError
+from zope.component.globalregistry import getGlobalSiteManager
 from zope.interface import implementedBy, providedBy
 
 
@@ -100,6 +101,14 @@
             yield registry
 
 
+def get_global_registry(context=None):
+    """Get current or global registry"""
+    registry = get_current_registry(context)
+    if registry is None:
+        registry = getGlobalSiteManager()
+    return registry
+
+
 def registered_utilities():
     """Get utilities registrations as generator