Added "copy_request" function
authorThierry Florac <thierry.florac@onf.fr>
Thu, 22 Feb 2018 11:04:56 +0100
changeset 143 0ee046374dae
parent 142 11be618da9c8
child 144 c9e3cfbbe4ad
Added "copy_request" function
src/pyams_utils/request.py
--- a/src/pyams_utils/request.py	Mon Feb 19 09:57:41 2018 +0100
+++ b/src/pyams_utils/request.py	Thu Feb 22 11:04:56 2018 +0100
@@ -128,6 +128,17 @@
         return request
 
 
+def copy_request(request):
+    """Create clone of given request, keeping registry as well"""
+    request = request.copy()
+    if not hasattr(request, 'registry'):
+        registry = get_current_registry()
+        if registry is None:
+            registry = get_global_registry()
+        request.registry = registry
+    return request
+
+
 def get_annotations(request):
     """Define 'annotations' request property