]> git.ipfire.org Git - pbs.git/commitdiff
web: Build function to easily compose URLs
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 4 Jun 2023 11:14:51 +0000 (11:14 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 4 Jun 2023 11:14:51 +0000 (11:14 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/templates/builds/index.html
src/web/__init__.py

index 8f49d5e509ef707fec166f1467d0d29abf958f8c..00cc01679fe91b7248bb4a01505ab831b946122f 100644 (file)
                        <div class="block">
                                <nav class="pagination is-centered" role="navigation" aria-label="pagination">
                                        <a class="pagination-previous {% if not offset %}is-disabled{% end %}"
-                                                       href="/builds?offset={{ offset - limit }}&limit={{ limit }}{% if user %}&user={{ user.name }}{% end %}">
+                                                       href="{{ make_url("/builds", offset=offset - limit, limit=limit, user=user.name if user else None) }}">
                                                {{ _("Previous Page") }}
                                        </a>
 
-                                       <a class="pagination-next" href="/builds?offset={{ offset + limit }}&limit={{ limit }}{% if user %}&user={{ user.name }}{% end %}">
+                                       <a class="pagination-next"
+                                                       href="{{ make_url("/builds", offset=offset + limit, limit=limit, user=user.name if user else None) }}">
                                                {{ _("Next Page") }}
                                        </a>
                                </nav>
index 5d5ce96e9bf85b3947672f3ddd869c7256fa978c..f0c68cd8efa300f0c9738cb66433e975183ee34c 100644 (file)
@@ -99,6 +99,7 @@ class Application(tornado.web.Application):
                                "extract_hostname"   : self.extract_hostname,
                                "format_time"        : self.format_time,
                                "group"              : self.group,
+                               "make_url"           : self.make_url,
                        },
                        xsrf_cookies = True,
                )
@@ -290,3 +291,12 @@ class Application(tornado.web.Application):
 
        def group(self, handler, *args, **kwargs):
                return misc.group(*args, **kwargs)
+
+       def make_url(self, handler, url, **kwargs):
+               # Format any query arguments and append them to the URL
+               if kwargs:
+                       args = urllib.parse.urlencode(kwargs)
+
+                       url = "%s?%s" % (url, args)
+
+               return url