mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-23 14:32:25 +01:00
Add option to hide non-free packages in API
This commit is contained in:
parent
2229b32c90
commit
328d05bdf6
10
app/utils.py
10
app/utils.py
@ -170,3 +170,13 @@ def clearNotifications(url):
|
|||||||
if current_user.is_authenticated:
|
if current_user.is_authenticated:
|
||||||
Notification.query.filter_by(user=current_user, url=url).delete()
|
Notification.query.filter_by(user=current_user, url=url).delete()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
|
YESES = ["yes", "true", "1", "on"]
|
||||||
|
|
||||||
|
def isYes(val):
|
||||||
|
return val and val.lower() in YESES
|
||||||
|
|
||||||
|
|
||||||
|
def isNo(val):
|
||||||
|
return val and not isYes(val)
|
||||||
|
@ -51,6 +51,7 @@ class QueryBuilder:
|
|||||||
self.types = types
|
self.types = types
|
||||||
self.search = request.args.get("q")
|
self.search = request.args.get("q")
|
||||||
self.lucky = "lucky" in request.args
|
self.lucky = "lucky" in request.args
|
||||||
|
self.hide_nonfree = isNo(request.args.get("nonfree"))
|
||||||
self.limit = 1 if self.lucky else None
|
self.limit = 1 if self.lucky else None
|
||||||
|
|
||||||
def buildPackageQuery(self):
|
def buildPackageQuery(self):
|
||||||
@ -64,6 +65,10 @@ class QueryBuilder:
|
|||||||
|
|
||||||
query = query.order_by(db.desc(Package.score))
|
query = query.order_by(db.desc(Package.score))
|
||||||
|
|
||||||
|
if self.hide_nonfree:
|
||||||
|
query = query.filter(Package.license.has(License.is_foss == True))
|
||||||
|
query = query.filter(Package.media_license.has(License.is_foss == True))
|
||||||
|
|
||||||
if self.limit:
|
if self.limit:
|
||||||
query = query.limit(self.limit)
|
query = query.limit(self.limit)
|
||||||
|
|
||||||
@ -78,6 +83,10 @@ class QueryBuilder:
|
|||||||
if len(self.types) > 0:
|
if len(self.types) > 0:
|
||||||
topics = topics.filter(ForumTopic.type.in_(self.types))
|
topics = topics.filter(ForumTopic.type.in_(self.types))
|
||||||
|
|
||||||
|
if self.hide_nonfree:
|
||||||
|
query = query.filter(Package.license.has(License.is_foss == True))
|
||||||
|
query = query.filter(Package.media_license.has(License.is_foss == True))
|
||||||
|
|
||||||
if self.limit:
|
if self.limit:
|
||||||
topics = topics.limit(self.limit)
|
topics = topics.limit(self.limit)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user