From 5c9a0de50b8667c6ad35513e60954110e945f87a Mon Sep 17 00:00:00 2001 From: Konrad Mohrfeldt <konrad.mohrfeldt@farbdev.org> Date: Fri, 26 Jan 2024 20:40:40 +0100 Subject: [PATCH] feat: remove default values for timeslot filter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The default values break some valid use cases and there’s no real value in applying them by default. refs #189 --- program/filters.py | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/program/filters.py b/program/filters.py index d32554aa..a212a42c 100644 --- a/program/filters.py +++ b/program/filters.py @@ -184,22 +184,13 @@ class TimeSlotFilterSet(filters.FilterSet): "If specified without a datetime value the current date and time is assumed." ), ) - # The start/end filters will always be applied even if no query parameter has been set. - # This is because we enforce a value in the clean_start and clean_end methods - # of the filterset form. start = filters.DateFilter( method="filter_start", - help_text=( - "Only returns timeslots after that start on or after the specified date. " - "By default, this is set to the current date." - ), + help_text="Only returns timeslots that start at or after the specified datetime.", ) end = filters.DateFilter( method="filter_end", - help_text=( - "Only returns timeslots that end on or before the specified date. " - "By default, this is set to value of the start filter + 60 days." - ), + help_text="Only returns timeslots that end before the specified datetime.", ) schedule_ids = IntegerInFilter( @@ -242,26 +233,6 @@ class TimeSlotFilterSet(filters.FilterSet): queryset = self.filter_surrounding(queryset, "surrounding", timezone.now()) return queryset - def get_form_class(self): - form_cls = super().get_form_class() - - class TimeSlotFilterSetFormWithDefaults(form_cls): - def clean_start(self): - start = self.cleaned_data.get("start", None) - return start or timezone.now().date() - - def clean_end(self): - end = self.cleaned_data.get("end", None) - return end or self.cleaned_data["start"] + datetime.timedelta(days=60) - - # We only want defaults to apply in the context of the list action. - # When accessing individual timeslots we don’t want the queryset to be restricted - # to the default range of 60 days as get_object would yield a 404 otherwise. - if self.request.parser_context["view"].action == "list": - return TimeSlotFilterSetFormWithDefaults - else: - return form_cls - class Meta: model = models.TimeSlot fields = [ -- GitLab