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)