diff --git a/app/flatpages/help/api.md b/app/flatpages/help/api.md index 6d2aadf0..6f30be25 100644 --- a/app/flatpages/help/api.md +++ b/app/flatpages/help/api.md @@ -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. diff --git a/app/querybuilder.py b/app/querybuilder.py index ad5e4667..143a7418 100644 --- a/app/querybuilder.py +++ b/app/querybuilder.py @@ -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))