Add support for filtering content warnings

This commit is contained in:
rubenwardy 2020-07-17 21:18:27 +01:00
parent 6a674c3c79
commit b067fd2e77
2 changed files with 26 additions and 15 deletions

View File

@ -8,19 +8,18 @@ your client to use new flags.
* `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.
* A content rating, given below. * A content warning, given below.
* `android_default` - meta-flag that filters out any content with a content warning.
* `desktop_default` - meta-flag that doesn't filter anything out for now.
## Warnings
## Ratings Packages with mature content will be tagged with a content warning based
on the content type.
Content ratings aren't currently supported by ContentDB. * `bad_language` - swearing.
Instead, mature content isn't allowed at all for now. * `drugs` - drugs or alcohol.
* `gambling`
In the future, more mature content will be allowed but labelled with * `gore` - blood, etc.
content ratings which may contain the following: * `horror` - shocking and scary content.
* `violence` - non-cartoon violence.
* android_default - meta-rating which includes gore and drugs.
* desktop_default - meta-rating which won't include anything for now.
* gore - more than just blood
* drugs
* swearing

View File

@ -1,4 +1,4 @@
from .models import db, PackageType, Package, ForumTopic, License, MinetestRelease, PackageRelease, User, Tag, Tags from .models import db, PackageType, Package, ForumTopic, License, MinetestRelease, PackageRelease, User, Tag, Tags, ContentWarning
from .utils import isNo, isYes, get_int_or_abort from .utils import isNo, isYes, get_int_or_abort
from sqlalchemy.sql.expression import func from sqlalchemy.sql.expression import func
from flask import abort from flask import abort
@ -27,17 +27,21 @@ class QueryBuilder:
# Hide # Hide
hide_flags = args.getlist("hide") hide_flags = args.getlist("hide")
self.title = title self.title = title
self.types = types self.types = types
self.tags = tags self.tags = tags
self.random = "random" in args self.random = "random" in args
self.lucky = "lucky" in args self.lucky = "lucky" in args
self.hide_nonfree = "nonfree" in hide_flags
self.limit = 1 if self.lucky else None self.limit = 1 if self.lucky else None
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"
self.hide_nonfree = "nonfree" in hide_flags
self.hide_flags = set(hide_flags)
self.hide_flags.discard("nonfree")
# Filters # Filters
self.search = args.get("q") self.search = args.get("q")
@ -112,6 +116,14 @@ 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:
query = query.filter(~ Package.content_warnings.any())
else:
for flag in self.hide_flags:
warning = ContentWarning.query.filter_by(name=flag).first()
if warning:
query = query.filter(~ Package.content_warnings.any(ContentWarning.id == warning.id))
if self.hide_nonfree: if self.hide_nonfree:
query = query.filter(Package.license.has(License.is_foss == True)) query = query.filter(Package.license.has(License.is_foss == True))
query = query.filter(Package.media_license.has(License.is_foss == True)) query = query.filter(Package.media_license.has(License.is_foss == True))