]> git.ipfire.org Git - pbs.git/commitdiff
jobs: Fix rendering the job index page
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 23 Jan 2025 10:05:42 +0000 (10:05 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 23 Jan 2025 10:05:42 +0000 (10:05 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/jobs.py
src/templates/jobs/index.html
src/web/jobs.py

index 141dbb24e761e363e308cb5c18e94c49c3f21930..4f076051dd32e1e6628bdffcfb09721c0c8ae33a 100644 (file)
@@ -616,6 +616,16 @@ class Job(database.Base, database.BackendMixin, database.SoftDeleteMixin):
 
        finished_at = Column(DateTime(timezone=False), nullable=False)
 
+       # Date
+
+       @property
+       def date(self):
+               if self.finished_at:
+                       return self.finished_at.date()
+
+               # Fall back on to today
+               return datetime.date.today()
+
        # Timeout
 
        timeout = Column(Interval)
index 4ba249d69102e17aa017fffe711b5473ba7dd4a4..07a240cef3c08d661f7dfb8b3699894246c1250f 100644 (file)
@@ -1,6 +1,8 @@
-{% extends "../base.html" %}
+{% extends "base.html" %}
 
-{% block title %}{{ _("Recent Jobs") }}{% end block %}
+{% from "jobs/macros.html" import JobQueue with context %}
+
+{% block title %}{{ _("Recent Jobs") }}{% endblock %}
 
 {% block body %}
        <section class="hero is-light">
                                                {{ _("Recently Failed Jobs") }}
                                        {% else %}
                                                {{ _("Recent Jobs") }}
-                                       {% end %}
+                                       {% endif %}
                                </h1>
 
                                <div class="buttons are-small">
-                                       <a class="button is-danger {% if not failed_only %}is-outlined{% end %}"
-                                                       href="{{ make_url("/jobs", offset=max(offset - limit, 0), limit=limit, failed_only=not failed_only) }}">
+                                       <a class="button is-danger {% if not failed_only %}is-outlined{% endif %}"
+                                                       href="{{ make_url("/jobs", offset=(offset - limit) if (offset - limit) > 0 else 0,
+                                                               limit=limit, failed_only=not failed_only) }}">
                                                {{ _("Failed") }}
                                        </a>
                                </div>
        <section class="section">
                <div class="container">
                        {# Render all jobs #}
-                       {% for date in jobs %}
+                       {% for date, items in jobs | groupby("date") %}
                                <div class="block">
-                                       <h4 class="title is-4">{{ locale.format_day(date) }}</h4>
+                                       <h4 class="title is-4">{{ date | format_day }}</h4>
 
-                                       {% module JobsQueue(jobs[date]) %}
+                                       {{ JobQueue(items) }}
                                </div>
-                       {% end %}
+                       {% endfor %}
 
                        <div class="block">
                                <nav class="pagination is-centered" role="navigation" aria-label="pagination">
-                                       <a class="pagination-previous {% if not offset %}is-disabled{% end %}"
+                                       <a class="pagination-previous {% if not offset %}is-disabled{% endif %}"
                                                        href="{{ make_url("/jobs", offset=offset - limit, limit=limit, failed_only=failed_only) }}">
                                                {{ _("Previous Page") }}
                                        </a>
@@ -60,4 +63,4 @@
                        </div>
                </div>
        </section>
-{% end block %}
+{% endblock %}
index d4ea530b0c8a0cab85fa06d8f25c2550d8e0c9f0..b405e6fd9032ed800eade564bb58ae4cd58511d6 100644 (file)
@@ -146,14 +146,14 @@ class IndexHandler(base.BaseHandler):
                # Filter
                failed_only = self.get_argument_bool("failed_only")
 
-               with self.db.transaction():
-                       jobs = self.backend.jobs.get_finished(failed_only=failed_only,
-                               limit=limit, offset=offset)
-
-                       # Group jobs by date
-                       jobs = await misc.group(jobs, lambda job: job.finished_at.date())
-
-               self.render("jobs/index.html", jobs=jobs, limit=limit, offset=offset,
+               # Fetch all finished jobs
+               jobs = self.backend.jobs.get_finished(
+                       failed_only = failed_only,
+                       limit       = limit,
+                       offset      = offset,
+               )
+
+               await self.render("jobs/index.html", jobs=jobs, limit=limit, offset=offset,
                        failed_only=failed_only)