From: Michael Tremer Date: Thu, 11 May 2023 14:06:42 +0000 (+0000) Subject: builds: Add pagination X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=20b9fe604f86c37bc1eef7b1f5becb60761942dc;p=pbs.git builds: Add pagination Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/builds.py b/src/buildservice/builds.py index 34870fa4..b63bc704 100644 --- a/src/buildservice/builds.py +++ b/src/buildservice/builds.py @@ -90,7 +90,7 @@ class Builds(base.Object): name, ) - def get_recent(self, limit=None): + def get_recent(self, limit=None, offset=None): """ Returns the most recent (non-test) builds """ @@ -105,8 +105,11 @@ class Builds(base.Object): test IS FALSE ORDER BY created_at DESC - LIMIT %s""", - limit, + LIMIT + %s + OFFSET + %s""", + limit, offset, ) return list(builds) diff --git a/src/templates/builds/index.html b/src/templates/builds/index.html index 03519f2d..8f49d5e5 100644 --- a/src/templates/builds/index.html +++ b/src/templates/builds/index.html @@ -31,6 +31,19 @@ {% module BuildsList(builds[date]) %} {% end %} + + {% end block %} diff --git a/src/web/builds.py b/src/web/builds.py index 81b25bc8..2d7c4b0f 100644 --- a/src/web/builds.py +++ b/src/web/builds.py @@ -63,19 +63,24 @@ class APIv1IndexHandler(base.APIMixin, base.BaseHandler): class IndexHandler(base.BaseHandler): def get(self): + # Pagination + offset = self.get_argument_int("offset", None) or 0 + limit = self.get_argument_int("limit", None) or 25 + # Filters user = self.get_argument_user("user", None) # Fetch the most recent builds if user: - builds = self.backend.builds.get_by_user(user, limit=25) + builds = self.backend.builds.get_by_user(user, limit=limit, offset=offset) else: - builds = self.backend.builds.get_recent(limit=25) + builds = self.backend.builds.get_recent(limit=limit, offset=offset) # Group builds by date builds = misc.group(builds, lambda build: build.created_at.date()) - self.render("builds/index.html", builds=builds, user=user) + self.render("builds/index.html", builds=builds, user=user, + limit=limit, offset=offset) class ShowHandler(base.BaseHandler):