Status-specific filters in status model

This commit is contained in:
Mouse Reeve 2021-10-06 11:19:13 -07:00
parent 34d6c88861
commit 53e5762563
2 changed files with 8 additions and 8 deletions

View file

@ -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(

View file

@ -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"
)