diff --git a/program/filters.py b/program/filters.py index f7669b5b647a85b2e4ebe1c1b56d475eb92eb5c3..331d7091f3221ab10b8375070f1624ab5f8309c7 100644 --- a/program/filters.py +++ b/program/filters.py @@ -5,7 +5,7 @@ from django_filters import rest_framework as filters from django_filters import widgets from django import forms -from django.db.models import Exists, OuterRef, Q, QuerySet +from django.db.models import Exists, OuterRef, QuerySet from django.utils import timezone from program import models @@ -74,11 +74,7 @@ class ShowFilterSet(StaticFilterHelpTextMixin, filters.FilterSet): ) is_active = filters.BooleanFilter( field_name="is_active", - method="filter_active", - help_text=( - "Return only currently running shows (with timeslots in the future) if true " - "or past or upcoming shows if false." - ), + help_text="Return only currently active/inactive shows.", ) is_writable = filters.BooleanFilter( method="filter_writable", @@ -121,34 +117,6 @@ class ShowFilterSet(StaticFilterHelpTextMixin, filters.FilterSet): help_text="Return only shows of the given type slug.", ) - def filter_active(self, queryset: QuerySet, name: str, value: bool): - # Filter currently running shows - # Get currently running schedules to filter by first - # For single dates we test if there'll be one in the future (and ignore the until date) - # TODO: Really consider first_date? (=currently active, not just upcoming ones) - # Add limit for future? - show_ids = ( - models.Schedule.objects.filter( - # not "once" schedules with first_date in the past and last_date in the future - Q( - rrule__freq__gt=0, - first_date__lte=timezone.now(), - last_date__gte=timezone.now(), - ) - # "once" schedules with first_date in the future - | Q(rrule__freq=0, first_date__gte=timezone.now()) - ) - .distinct() - .values_list("show_id", flat=True) - ) - if value: - # Filter active shows based on timeslots as well as on the is_active flag - # Even if there are future timeslots but is_active=True the show will be considered as - # inactive - return queryset.filter(id__in=show_ids, is_active=True) - else: - return queryset.exclude(id__in=show_ids, is_active=True) - def filter_writable(self, queryset: QuerySet, _: str, value: bool) -> QuerySet: user = self.request.user if self.request.user.is_authenticated else None