Add view decorator to set an explicit xkey
authorMagnus Hagander <magnus@hagander.net>
Wed, 13 Aug 2025 07:57:50 +0000 (09:57 +0200)
committerMagnus Hagander <magnus@hagander.net>
Wed, 13 Aug 2025 10:15:04 +0000 (12:15 +0200)
pgweb/util/decorators.py

index c893973c3427b938649ce27f1f195795674ef12b..dbd39e58622eaadf772490fd70fee247e199b19e 100644 (file)
@@ -24,6 +24,20 @@ def cache(days=0, hours=0, minutes=0, seconds=0):
     return _cache
 
 
+def xkey(key):
+    "Add a specific xkey to the page, other than the auto-generated ones"
+    def _xkey(fn):
+        def __xkey(request, *_args, **_kwargs):
+            resp = fn(request, *_args, **_kwargs)
+            if 'xkey' in resp:
+                resp['xkey'] += ' ' + key
+            else:
+                resp['xkey'] = key
+            return resp
+        return __xkey
+    return _xkey
+
+
 def queryparams(*args):
     """
     Allow specified query parameters when calling function.