From 66c4ac66af3b0e8e9adc1c9ef92df3b599baab73 Mon Sep 17 00:00:00 2001 From: Michael Reid Date: Thu, 27 Apr 2023 07:48:16 -0400 Subject: [PATCH] Implement package filter for active build (#98) * Add hybrid property 'any_builds_active' to Version model * Add hybrid property 'any_builds_active' to Package model * Modify Flask route to check that 'package' contains active builds --------- Co-authored-by: Antoine Bertin --- spkrepo/models.py | 8 ++++++++ spkrepo/views/frontend.py | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/spkrepo/models.py b/spkrepo/models.py index 8b7d3b8..5a7c957 100644 --- a/spkrepo/models.py +++ b/spkrepo/models.py @@ -444,6 +444,10 @@ def beta(self): def all_builds_active(self): return all(b.active for b in self.builds) + @hybrid_property + def any_builds_active(self): + return any(b.active for b in self.builds) + @all_builds_active.expression def all_builds_active(cls): return ( @@ -532,6 +536,10 @@ class Package(db.Model): # Constraints __table_args__ = (db.UniqueConstraint(name),) + @hybrid_property + def any_builds_active(self): + return any(v.any_builds_active for v in self.versions) + @classmethod def find(cls, name): return cls.query.filter(cls.name == name).first() diff --git a/spkrepo/views/frontend.py b/spkrepo/views/frontend.py index af5f170..0289986 100644 --- a/spkrepo/views/frontend.py +++ b/spkrepo/views/frontend.py @@ -96,9 +96,9 @@ def packages(): @frontend.route("/package/") def package(name): - # TODO: show only packages with at least a version and an active build + # show only packages with at least a version and an active build package = Package.query.filter_by(name=name).first() - if package is None: + if package is None or not package.any_builds_active: abort(404) return render_template("frontend/package.html", package=package)