Add top reviewed section to homepage

This commit is contained in:
rubenwardy 2020-12-14 11:48:07 +00:00
parent fc9b8c2a5a
commit fc8cd3cfb8
4 changed files with 16 additions and 4 deletions

@ -22,12 +22,14 @@ def home():
pop_mod = join(query.filter_by(type=PackageType.MOD).order_by(db.desc(Package.score))).limit(8).all() pop_mod = join(query.filter_by(type=PackageType.MOD).order_by(db.desc(Package.score))).limit(8).all()
pop_gam = join(query.filter_by(type=PackageType.GAME).order_by(db.desc(Package.score))).limit(4).all() pop_gam = join(query.filter_by(type=PackageType.GAME).order_by(db.desc(Package.score))).limit(4).all()
pop_txp = join(query.filter_by(type=PackageType.TXP).order_by(db.desc(Package.score))).limit(4).all() pop_txp = join(query.filter_by(type=PackageType.TXP).order_by(db.desc(Package.score))).limit(4).all()
high_reviewed = join(query.order_by(db.desc(Package.score - Package.score_downloads))) \
.filter(Package.reviews.any()).limit(4).all()
updated = db.session.query(Package).select_from(PackageRelease).join(Package) \ updated = db.session.query(Package).select_from(PackageRelease).join(Package) \
.filter_by(state=PackageState.APPROVED) \ .filter_by(state=PackageState.APPROVED) \
.order_by(db.desc(PackageRelease.releaseDate)) \ .order_by(db.desc(PackageRelease.releaseDate)) \
.limit(20).all() .limit(20).all()
updated = updated[:8] updated = updated[:4]
reviews = PackageReview.query.filter_by(recommends=True).order_by(db.desc(PackageReview.created_at)).limit(5).all() reviews = PackageReview.query.filter_by(recommends=True).order_by(db.desc(PackageReview.created_at)).limit(5).all()
@ -38,4 +40,4 @@ def home():
.select_from(Tag).outerjoin(Tags).group_by(Tag.id).order_by(db.asc(Tag.title)).all() .select_from(Tag).outerjoin(Tags).group_by(Tag.id).order_by(db.asc(Tag.title)).all()
return render_template("index.html", count=count, downloads=downloads, tags=tags, return render_template("index.html", count=count, downloads=downloads, tags=tags,
new=new, updated=updated, pop_mod=pop_mod, pop_txp=pop_txp, pop_gam=pop_gam, reviews=reviews) new=new, updated=updated, pop_mod=pop_mod, pop_txp=pop_txp, pop_gam=pop_gam, high_reviewed=high_reviewed, reviews=reviews)

@ -66,7 +66,7 @@ Supported query parameters:
* `random` - When present, enable random ordering and ignore `sort`. * `random` - When present, enable random ordering and ignore `sort`.
* `limit` - Return at most `limit` packages. * `limit` - Return at most `limit` packages.
* `hide` - Hide content based on [Content Flags](/help/content_flags/). * `hide` - Hide content based on [Content Flags](/help/content_flags/).
* `sort` - Sort by (`name`, `title`, `score`, `downloads`, `created_at`, `approved_at`, `last_release`). * `sort` - Sort by (`name`, `title`, `score`, `reviews`, `downloads`, `created_at`, `approved_at`, `last_release`).
* `order` - Sort ascending (`asc`) or descending (`desc`). * `order` - Sort ascending (`asc`) or descending (`desc`).
* `protocol_version` - Only show packages supported by this Minetest protocol version. * `protocol_version` - Only show packages supported by this Minetest protocol version.
* `engine_version` - Only show packages supported by this Minetest engine version, eg: `5.3.0`. * `engine_version` - Only show packages supported by this Minetest engine version, eg: `5.3.0`.

@ -131,6 +131,9 @@ class QueryBuilder:
pass pass
elif self.order_by is None or self.order_by == "score": elif self.order_by is None or self.order_by == "score":
to_order = Package.score to_order = Package.score
elif self.order_by == "reviews":
query = query.filter(Package.reviews.any())
to_order = (Package.score - Package.score_downloads)
elif self.order_by == "name": elif self.order_by == "name":
to_order = Package.name to_order = Package.name
elif self.order_by == "title": elif self.order_by == "title":
@ -146,7 +149,7 @@ class QueryBuilder:
else: else:
abort(400) abort(400)
if to_order: if to_order is not None:
if self.order_dir == "asc": if self.order_dir == "asc":
to_order = db.asc(to_order) to_order = db.asc(to_order)
elif self.order_dir == "desc": elif self.order_dir == "desc":

@ -73,6 +73,13 @@
<div class="clearfix mb-4"></div> <div class="clearfix mb-4"></div>
<a href="{{ url_for('packages.list_all', sort='reviews', order='desc') }}" class="btn btn-secondary float-right">
{{ _("See more") }}
</a>
<h2 class="my-3">{{ _("Top Reviewed") }}</h2>
{{ render_pkggrid(high_reviewed) }}
<a href="{{ url_for('packages.list_reviews') }}" class="btn btn-secondary float-right"> <a href="{{ url_for('packages.list_reviews') }}" class="btn btn-secondary float-right">
{{ _("See more") }} {{ _("See more") }}
</a> </a>