Skip to content

Commit

Permalink
Implement package filter for active build (#98)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
mreid-tt and Diaoul authored Apr 27, 2023
1 parent 2b7462b commit 66c4ac6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions spkrepo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions spkrepo/views/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ def packages():

@frontend.route("/package/<name>")
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)

Expand Down

0 comments on commit 66c4ac6

Please sign in to comment.