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) query = Package.query.filter_by(approved=True, soft_deleted=False)
count = query.count() 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_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()

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

@ -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`, `last_release`). * `sort` - Sort by (`name`, `title`, `score`, `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`.

@ -98,6 +98,8 @@ class QueryBuilder:
to_order = Package.downloads to_order = Package.downloads
elif self.order_by == "created_at" or self.order_by == "date": elif self.order_by == "created_at" or self.order_by == "date":
to_order = Package.created_at 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": elif self.order_by == "last_release":
to_order = PackageRelease.releaseDate to_order = PackageRelease.releaseDate
else: else:

@ -23,7 +23,7 @@
{% from "macros/packagegridtile.html" import render_pkggrid %} {% 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") }} {{ _("See more") }}
</a> </a>
<h2 class="my-3">{{ _("Recently Added") }}</h2> <h2 class="my-3">{{ _("Recently Added") }}</h2>