From: Michael Tremer Date: Thu, 23 Jan 2025 10:05:42 +0000 (+0000) Subject: jobs: Fix rendering the job index page X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b85af13c3022bb06b5fd5a590731a4c3c5b2604b;p=pbs.git jobs: Fix rendering the job index page Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/jobs.py b/src/buildservice/jobs.py index 141dbb24..4f076051 100644 --- a/src/buildservice/jobs.py +++ b/src/buildservice/jobs.py @@ -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) diff --git a/src/templates/jobs/index.html b/src/templates/jobs/index.html index 4ba249d6..07a240ce 100644 --- a/src/templates/jobs/index.html +++ b/src/templates/jobs/index.html @@ -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 %}
@@ -21,12 +23,13 @@ {{ _("Recently Failed Jobs") }} {% else %} {{ _("Recent Jobs") }} - {% end %} + {% endif %} @@ -37,17 +40,17 @@
{# Render all jobs #} - {% for date in jobs %} + {% for date, items in jobs | groupby("date") %}
-

{{ locale.format_day(date) }}

+

{{ date | format_day }}

- {% module JobsQueue(jobs[date]) %} + {{ JobQueue(items) }}
- {% end %} + {% endfor %}
-{% end block %} +{% endblock %} diff --git a/src/web/jobs.py b/src/web/jobs.py index d4ea530b..b405e6fd 100644 --- a/src/web/jobs.py +++ b/src/web/jobs.py @@ -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)