From 53e576256313bdd45f4a7e43ecb3b810a075446e Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 6 Oct 2021 11:19:13 -0700 Subject: [PATCH] Status-specific filters in status model --- bookwyrm/models/base_model.py | 8 +------- bookwyrm/models/status.py | 8 +++++++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bookwyrm/models/base_model.py b/bookwyrm/models/base_model.py index 06445a11d..d32ec67be 100644 --- a/bookwyrm/models/base_model.py +++ b/bookwyrm/models/base_model.py @@ -2,7 +2,7 @@ import base64 from Crypto import Random -from django.core.exceptions import PermissionDenied, FieldError +from django.core.exceptions import PermissionDenied from django.db import models from django.db.models import Q from django.dispatch import receiver @@ -120,12 +120,6 @@ class BookWyrmModel(models.Model): p for p in privacy_levels if not p in ["followers", "direct"] ] - # if there's a deleted field, exclude deleted items - try: - queryset = queryset.filter(deleted=False) - except FieldError: - pass - # exclude blocks from both directions if not viewer.is_anonymous: queryset = queryset.exclude( diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 3e5f638f5..1325aa884 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -6,6 +6,7 @@ from django.apps import apps from django.core.exceptions import PermissionDenied from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models +from django.db.models import Q from django.dispatch import receiver from django.template.loader import get_template from django.utils import timezone @@ -207,9 +208,14 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): if isinstance(self, (GeneratedNote, ReviewRating)): raise PermissionDenied() + @classmethod + def privacy_filter(cls, viewer, privacy_levels=None): + queryset = super().privacy_filter(viewer, privacy_levels=privacy_levels) + return queryset.filter(deleted=False) + @classmethod def direct_filter(cls, queryset, viewer): - """Override-able filter for "direct" privacy level""" + """Overridden filter for "direct" privacy level""" return queryset.exclude( ~Q(Q(user=viewer) | Q(mention_users=viewer)), privacy="direct" )