Clean up `hide` query argument in QueryBuilder

This commit is contained in:
rubenwardy 2021-12-20 21:24:06 +00:00
parent 5d32d7922f
commit 5932ac3c7c
2 changed files with 25 additions and 19 deletions

View File

@ -15,25 +15,27 @@ contentdb_flag_blacklist = nonfree, bad_language, drugs
A flag can be:
* `nonfree` - can be used to hide packages which do not qualify as
* `nonfree`: can be used to hide packages which do not qualify as
'free software', as defined by the Free Software Foundation.
* `wip` - packages marked as Work in Progress
* `deprecated` - packages marked as Deprecated
* `wip`: packages marked as Work in Progress
* `deprecated`: packages marked as Deprecated
* A content warning, given below.
* `android_default` - meta-flag that filters out any content with a content warning and WIP packages
* `desktop_default` - meta-flag that filters out WIP packages.
* `*`: hides all content warnings.
The `_default` flags are designed so that we can change how different platforms filter the package list
based on
There are also two meta-flags, which are designed so that we can change how different platforms filter the package list
without making a release.
* `android_default`: currently same as `*, wip, deprecated`. Hides all content warnings, WIP packages, and deprecated packages
* `desktop_default`: currently same as `wip, deprecated`. Hides all WIP and deprecated packages
## Content Warnings
Packages with mature content will be tagged with a content warning based
on the content type.
* `bad_language` - swearing.
* `drugs` - drugs or alcohol.
* `bad_language`: swearing.
* `drugs`: drugs or alcohol.
* `gambling`
* `gore` - blood, etc.
* `horror` - shocking and scary content.
* `violence` - non-cartoon violence.
* `gore`: blood, etc.
* `horror`: shocking and scary content.
* `violence`: non-cartoon violence.

View File

@ -29,7 +29,7 @@ class QueryBuilder:
tags = [tag for tag in tags if tag is not None]
# Hide
hide_flags = args.getlist("hide")
self.hide_flags = set(args.getlist("hide"))
self.title = title
self.types = types
@ -41,13 +41,17 @@ class QueryBuilder:
self.order_by = args.get("sort")
self.order_dir = args.get("order") or "desc"
use_platform_defaults = "android_default" in hide_flags or "desktop_default" in hide_flags
if "android_default" in self.hide_flags:
self.hide_flags.update(["*", "wip", "deprecated"])
self.hide_flags.discard("android_default")
self.hide_nonfree = "nonfree" in hide_flags
self.hide_wip = "wip" in hide_flags or use_platform_defaults
self.hide_deprecated = "deprecated" in hide_flags or use_platform_defaults
if "desktop_default" in self.hide_flags:
self.hide_flags.update(["wip", "deprecated"])
self.hide_flags.discard("desktop_default")
self.hide_flags = set(hide_flags)
self.hide_nonfree = "nonfree" in self.hide_flags
self.hide_wip = "wip" in self.hide_flags
self.hide_deprecated = "deprecated" in self.hide_flags
self.hide_flags.discard("nonfree")
self.hide_flags.discard("wip")
self.hide_flags.discard("deprecated")
@ -131,7 +135,7 @@ class QueryBuilder:
for tag in self.tags:
query = query.filter(Package.tags.any(Tag.id == tag.id))
if "android_default" in self.hide_flags:
if "*" in self.hide_flags:
query = query.filter(~ Package.content_warnings.any())
else:
for flag in self.hide_flags: