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

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

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