changeset 1463:2c8449885272

pages: query parameters can now be specified using keyword arguments in `getURL:` rel: 399
author Goffi <goffi@goffi.org>
date Thu, 30 Sep 2021 16:57:54 +0200
parents 87e48b6a1bbd
children a8435aebfbcc
files libervia/server/pages.py
diffstat 1 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/server/pages.py	Thu Sep 30 11:55:42 2021 +0200
+++ b/libervia/server/pages.py	Thu Sep 30 16:57:54 2021 +0200
@@ -665,11 +665,12 @@
             else url.encode("utf-8"),
         )
 
-    def getURL(self, *args: str) -> str:
+    def getURL(self, *args: str, **kwargs: str) -> str:
         """retrieve URL of the page set arguments
 
         @param *args: arguments to add to the URL as path elements empty or None
             arguments will be ignored
+        @param **kwargs: query parameters
         """
         url_args = [quote(a) for a in args if a]
 
@@ -683,11 +684,20 @@
                     url_base = redirect_data[current_hash]
                     remaining = args[limit:]
                     remaining_url = "/".join(remaining)
-                    return os.path.join("/", url_base, remaining_url)
+                    url = os.path.join("/", url_base, remaining_url)
+                    break
+        else:
+            url = os.path.join(self.url, *url_args)
+
+        if kwargs:
+            encoded = urllib.parse.urlencode(
+                {k: v for k, v in kwargs.items()}
+            )
+            url +=  f"?{encoded}"
 
         return self.host.checkRedirection(
             self.vhost_root,
-            os.path.join(self.url, *url_args)
+            url
         )
 
     def getCurrentURL(self, request):