mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-25 23:41:33 +01:00
Add sort and order query params to package list
This commit is contained in:
parent
5f40d68441
commit
fd901726b0
@ -29,14 +29,14 @@ Welcome
|
|||||||
{{ render_pkggrid(new) }}
|
{{ render_pkggrid(new) }}
|
||||||
|
|
||||||
|
|
||||||
<a href="{{ url_for('packages_page') }}" class="btn btn-secondary float-right">
|
<a href="{{ url_for('packages_page', sort='score', order='desc') }}" class="btn btn-secondary float-right">
|
||||||
See more
|
See more
|
||||||
</a>
|
</a>
|
||||||
<h2 class="my-3">Popular</h2>
|
<h2 class="my-3">Popular</h2>
|
||||||
{{ render_pkggrid(popular) }}
|
{{ render_pkggrid(popular) }}
|
||||||
|
|
||||||
|
|
||||||
<a href="{{ url_for('packages_page', type='txp') }}" class="btn btn-secondary float-right">
|
<a href="{{ url_for('packages_page', type='txp', sort='score', order='desc') }}" class="btn btn-secondary float-right">
|
||||||
See more
|
See more
|
||||||
</a>
|
</a>
|
||||||
<h2 class="my-3">Top Texture Packs</h2>
|
<h2 class="my-3">Top Texture Packs</h2>
|
||||||
|
@ -53,6 +53,8 @@ class QueryBuilder:
|
|||||||
self.lucky = "lucky" in request.args
|
self.lucky = "lucky" in request.args
|
||||||
self.hide_nonfree = isNo(request.args.get("nonfree"))
|
self.hide_nonfree = isNo(request.args.get("nonfree"))
|
||||||
self.limit = 1 if self.lucky else None
|
self.limit = 1 if self.lucky else None
|
||||||
|
self.order_by = request.args.get("sort") or "score"
|
||||||
|
self.order_dir = request.args.get("order") or "desc"
|
||||||
|
|
||||||
def buildPackageQuery(self):
|
def buildPackageQuery(self):
|
||||||
query = Package.query.filter_by(soft_deleted=False, approved=True)
|
query = Package.query.filter_by(soft_deleted=False, approved=True)
|
||||||
@ -63,7 +65,22 @@ class QueryBuilder:
|
|||||||
if self.search is not None and self.search.strip() != "":
|
if self.search is not None and self.search.strip() != "":
|
||||||
query = query.filter(Package.title.ilike('%' + self.search + '%'))
|
query = query.filter(Package.title.ilike('%' + self.search + '%'))
|
||||||
|
|
||||||
query = query.order_by(db.desc(Package.score))
|
to_order = None
|
||||||
|
if self.order_by == "score":
|
||||||
|
to_order = Package.score
|
||||||
|
elif self.order_by == "created_at":
|
||||||
|
to_order = Package.created_at
|
||||||
|
else:
|
||||||
|
abort(400)
|
||||||
|
|
||||||
|
if self.order_dir == "asc":
|
||||||
|
to_order = db.asc(to_order)
|
||||||
|
elif self.order_dir == "desc":
|
||||||
|
to_order = db.desc(to_order)
|
||||||
|
else:
|
||||||
|
abort(400)
|
||||||
|
|
||||||
|
query = query.order_by(to_order)
|
||||||
|
|
||||||
if self.hide_nonfree:
|
if self.hide_nonfree:
|
||||||
query = query.filter(Package.license.has(License.is_foss == True))
|
query = query.filter(Package.license.has(License.is_foss == True))
|
||||||
|
Loading…
Reference in New Issue
Block a user