Add 'queryRequest' function to get null request when there is no interaction ZTK-1.1
authorThierry Florac
Sat, 10 Dec 2011 01:33:04 +0100
branchZTK-1.1
changeset 92 bf59a3d6e437
parent 91 9bd1b95afc93
child 94 a5fb6eed0a5d
child 103 088a873802df
Add 'queryRequest' function to get null request when there is no interaction
ztfy/utils/request.py
--- a/ztfy/utils/request.py	Sat Dec 10 01:32:15 2011 +0100
+++ b/ztfy/utils/request.py	Sat Dec 10 01:33:04 2011 +0100
@@ -28,6 +28,7 @@
 # import local packages
 
 from ztfy.utils import _
+from zope.security.interfaces import NoInteraction
 
 
 def getRequest():
@@ -39,6 +40,13 @@
     raise RuntimeError, _("No Request in interaction !")
 
 
+def queryRequest():
+    try:
+        return getRequest()
+    except NoInteraction:
+        return None
+
+
 def getRequestPrincipal(request=None):
     """Get principal from given request"""
     if request is None: