Sort "recently added" by approved_at

This commit is contained in:
rubenwardy 2020-07-18 01:48:21 +01:00
parent 7d0a93483a
commit c7b1dcec4f
5 changed files with 7 additions and 4 deletions

@ -18,7 +18,7 @@ def home():
query = Package.query.filter_by(approved=True, soft_deleted=False)
count = query.count()
new = join(query.order_by(db.desc(Package.created_at))).limit(8).all()
new = join(query.order_by(db.desc(Package.approved_at))).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_txp = join(query.filter_by(type=PackageType.TXP).order_by(db.desc(Package.score))).limit(4).all()

@ -367,6 +367,7 @@ def approve(package):
else:
package.approved = True
if not package.approved_at:
package.approved_at = datetime.datetime.now()
screenshots = PackageScreenshot.query.filter_by(package=package, approved=False).all()

@ -66,7 +66,7 @@ Supported query parameters:
* `random` - When present, enable random ordering and ignore `sort`.
* `limit` - Return at most `limit` packages.
* `hide` - Hide content based on [Content Flags](/help/content_flags/).
* `sort` - Sort by (`name`, `title`, `score`, `downloads`, `created_at`, `last_release`).
* `sort` - Sort by (`name`, `title`, `score`, `downloads`, `created_at`, `approved_at`, `last_release`).
* `order` - Sort ascending (`asc`) or descending (`desc`).
* `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`.

@ -98,6 +98,8 @@ class QueryBuilder:
to_order = Package.downloads
elif self.order_by == "created_at" or self.order_by == "date":
to_order = Package.created_at
elif self.order_by == "approved_at" or self.order_by == "date":
to_order = Package.approved_at
elif self.order_by == "last_release":
to_order = PackageRelease.releaseDate
else:

@ -23,7 +23,7 @@
{% from "macros/packagegridtile.html" import render_pkggrid %}
<a href="{{ url_for('packages.list_all', sort='created_at', order='desc') }}" class="btn btn-secondary float-right">
<a href="{{ url_for('packages.list_all', sort='approved_at', order='desc') }}" class="btn btn-secondary float-right">
{{ _("See more") }}
</a>
<h2 class="my-3">{{ _("Recently Added") }}</h2>