]> git.ipfire.org Git - pbs.git/commitdiff
builds: Refactor index handler
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Jun 2022 09:25:54 +0000 (09:25 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Jun 2022 09:25:54 +0000 (09:25 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/buildservice/builds.py
src/templates/builds/index.html [moved from src/templates/build-index.html with 97% similarity]
src/web/__init__.py
src/web/builds.py

index f4bd857123006bcd910d6ef875bfa46b856e47ba..2c9f9e13b449d48e1592682b212e70ae7f96e8f0 100644 (file)
@@ -150,7 +150,6 @@ dist_templates_DATA = \
        src/templates/build-bugs.html \
        src/templates/build-delete.html \
        src/templates/build-filter.html \
-       src/templates/build-index.html \
        src/templates/build-list.html \
        src/templates/build-manage.html \
        src/templates/build-priority.html \
@@ -209,6 +208,7 @@ templates_buildersdir = $(templatesdir)/builders
 
 dist_templates_builds_DATA = \
        src/templates/builds/comments.html \
+       src/templates/builds/index.html \
        src/templates/builds/show.html
 
 templates_buildsdir = $(templatesdir)/builds
index 65fb060a97d3eb567890715aa2c16519745f431f..42fe985ef5ea916159508088002b01240f2a5fd8 100644 (file)
@@ -28,11 +28,6 @@ class Builds(base.Object):
                for row in res:
                        yield Build(self.backend, row.id, data=row)
 
-       def __iter__(self):
-               builds = self._get_builds("SELECT * FROM builds ORDER BY time_created DESC")
-
-               return iter(builds)
-
        def get_by_id(self, id, data=None):
                return Build(self.backend, id, data=data)
 
@@ -122,6 +117,23 @@ class Builds(base.Object):
                        name,
                )
 
+       def get_recent(self, limit=None):
+               """
+                       Returns the most recent builds
+               """
+               builds = self._get_builds("""
+                       SELECT
+                               *
+                       FROM
+                               builds
+                       ORDER BY
+                               time_created DESC
+                       LIMIT %s""",
+                       limit,
+               )
+
+               return list(builds)
+
        def get_obsolete(self, repo=None):
                """
                        Get all obsoleted builds.
similarity index 97%
rename from src/templates/build-index.html
rename to src/templates/builds/index.html
index 3eb4dd0fc5d56df16cc5ef7c1c3e11af247d50e1..a19591cf5341aa06fdf0b01f9c24ffae8fde19dd 100644 (file)
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "../base.html" %}
 
 {% block title %}{{ _("Builds") }}{% end block %}
 
index 02f65f661356219a4280f74b6c4e409fc2e3d780..2df8973b5fff553cc5abef95c13e267f5b6e8081 100644 (file)
@@ -124,7 +124,7 @@ class Application(tornado.web.Application):
                        (r"/file/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})", FileDetailHandler),
 
                        # Builds
-                       (r"/builds", builds.BuildsHandler),
+                       (r"/builds", builds.IndexHandler),
                        (r"/builds/comments", builds.BuildsCommentsHandler),
                        (r"/builds/comments/(\w+)", builds.BuildsCommentsHandler),
                        (r"/builds/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})", builds.ShowHandler),
index a6daa2533548bca31273740d52175426557b94b4..e1141e755d7ec864aead3d1715983a01fb09b132 100644 (file)
@@ -4,24 +4,6 @@ import tornado.web
 
 from . import base
 
-class BuildsHandler(base.BaseHandler):
-       def get(self):
-               limit = self.get_argument("limit", None)
-               try:
-                       limit = int(limit)
-               except (TypeError, ValueError):
-                       limit = 25
-
-               builds = []
-               for build in self.backend.builds:
-                       builds.append(build)
-
-                       limit -= 1
-                       if not limit:
-                               break
-
-               self.render("build-index.html", builds=builds)
-
 
 class BuildBaseHandler(base.BaseHandler):
        def get_build(self, uuid):
@@ -32,6 +14,14 @@ class BuildBaseHandler(base.BaseHandler):
                return build
 
 
+class IndexHandler(base.BaseHandler):
+       def get(self):
+               # Fetch the most recent builds
+               builds = self.backend.builds.get_recent(limit=25)
+
+               self.render("builds/index.html", builds=builds)
+
+
 class ShowHandler(BuildBaseHandler):
        def get(self, uuid):
                build = self.backend.builds.get_by_uuid(uuid)