From: rubenwardy Date: Fri, 17 Jul 2020 20:18:27 +0000 (+0100) Subject: Add support for filtering content warnings X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=b067fd2e773409790cb86cff1f799ad1563ea480;p=cheatdb.git Add support for filtering content warnings --- diff --git a/app/flatpages/help/content_flags.md b/app/flatpages/help/content_flags.md index ef20dbc..733ccb8 100644 --- a/app/flatpages/help/content_flags.md +++ b/app/flatpages/help/content_flags.md @@ -8,19 +8,18 @@ your client to use new flags. * `nonfree` - can be used to hide packages which do not qualify as '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. -Instead, mature content isn't allowed at all for now. - -In the future, more mature content will be allowed but labelled with -content ratings which may contain the following: - -* 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 +* `bad_language` - swearing. +* `drugs` - drugs or alcohol. +* `gambling` +* `gore` - blood, etc. +* `horror` - shocking and scary content. +* `violence` - non-cartoon violence. diff --git a/app/querybuilder.py b/app/querybuilder.py index c4823cb..922438e 100644 --- a/app/querybuilder.py +++ b/app/querybuilder.py @@ -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 sqlalchemy.sql.expression import func from flask import abort @@ -27,17 +27,21 @@ class QueryBuilder: # Hide hide_flags = args.getlist("hide") + self.title = title self.types = types self.tags = tags self.random = "random" in args self.lucky = "lucky" in args - self.hide_nonfree = "nonfree" in hide_flags self.limit = 1 if self.lucky else None self.order_by = args.get("sort") 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 self.search = args.get("q") @@ -112,6 +116,14 @@ class QueryBuilder: for tag in self.tags: 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: query = query.filter(Package.license.has(License.is_foss == True)) query = query.filter(Package.media_license.has(License.is_foss == True))