mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-22 22:12:24 +01:00
Add query arg to show packages with flag
This commit is contained in:
parent
a9ae14af9a
commit
35701b1097
@ -186,6 +186,7 @@ Supported query parameters:
|
||||
* `q`: Query string.
|
||||
* `author`: Filter by author.
|
||||
* `tag`: Filter by tags.
|
||||
* `flag`: Filter to show packages with [Content Flags](/help/content_flags/).
|
||||
* `game`: Filter by [Game Support](/help/game_support/), ex: `Wuzzy/mineclone2`. (experimental, doesn't show items that support every game currently).
|
||||
* `random`: When present, enable random ordering and ignore `sort`.
|
||||
* `limit`: Return at most `limit` packages.
|
||||
|
@ -70,6 +70,9 @@ class QueryBuilder:
|
||||
# Hide
|
||||
self.hide_flags = set(args.getlist("hide"))
|
||||
|
||||
# Show flags
|
||||
self.flags = set(args.getlist("flag"))
|
||||
|
||||
self.types = types
|
||||
self.tags = tags
|
||||
|
||||
@ -188,6 +191,27 @@ class QueryBuilder:
|
||||
if warning:
|
||||
query = query.filter(~ Package.content_warnings.any(ContentWarning.id == warning.id))
|
||||
|
||||
flags = set(self.flags)
|
||||
if "nonfree" in flags:
|
||||
query = query.filter(or_(Package.license.has(is_foss=False), Package.media_license.has(is_foss=False)))
|
||||
flags.discard("nonfree")
|
||||
if "wip" in flags:
|
||||
query = query.filter(Package.dev_state == PackageDevState.WIP)
|
||||
flags.discard("wip")
|
||||
if "deprecated" in flags:
|
||||
query = query.filter(Package.dev_state == PackageDevState.DEPRECATED)
|
||||
flags.discard("deprecated")
|
||||
|
||||
if "*" in flags:
|
||||
query = query.filter(Package.content_warnings.any())
|
||||
flags.discard("*")
|
||||
else:
|
||||
for flag in flags:
|
||||
warning = ContentWarning.query.filter_by(name=flag).first()
|
||||
flags.discard(flag)
|
||||
if warning:
|
||||
query = query.filter(Package.content_warnings.any(ContentWarning.id == warning.id))
|
||||
|
||||
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))
|
||||
|
Loading…
Reference in New Issue
Block a user