]> git.lizzy.rs Git - cheatdb.git/commitdiff
Add support for filtering content warnings
authorrubenwardy <rw@rubenwardy.com>
Fri, 17 Jul 2020 20:18:27 +0000 (21:18 +0100)
committerrubenwardy <rw@rubenwardy.com>
Fri, 17 Jul 2020 20:18:27 +0000 (21:18 +0100)
app/flatpages/help/content_flags.md
app/querybuilder.py

index ef20dbca92cd9807a8ce806d78b0efdc29323343..733ccb869ac9d0c8a8f4632052894c6f1a2e719d 100644 (file)
@@ -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.
index c4823cb31776899b2a397dfd8c54b5fc7f4b2673..922438e613c9a6b261cc1eeb740e730733373600 100644 (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 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))