Skip to content
Snippets Groups Projects
Commit 3c38698a authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt :koala:
Browse files

fix: don’t restrict timeslot queryset on detail views

The filter defaults caused the queryset to always yield results filtered
for the coming 60 days. We should only apply filter defaults when
listing timeslots, not when querying individual items.
parent 5bc1f22b
No related branches found
No related tags found
1 merge request!21Add API documentation
......@@ -3,7 +3,6 @@ import datetime
from django_filters import rest_framework as filters
from django_filters import widgets
from django import forms
from django.contrib.auth.models import User
from django.db.models import Q, QuerySet
from django.utils import timezone
......@@ -182,16 +181,10 @@ class TimeSlotFilterSet(filters.FilterSet):
queryset = self.filter_surrounding(queryset, "surrounding", timezone.now())
return queryset
class Meta:
model = models.TimeSlot
fields = [
"order",
"start",
"end",
"surrounding",
]
def get_form_class(self):
form_cls = super().get_form_class()
class form(forms.Form):
class TimeSlotFilterSetFormWithDefaults(form_cls):
def clean_start(self):
start = self.cleaned_data.get("start", None)
return start or timezone.now().date()
......@@ -200,6 +193,23 @@ class TimeSlotFilterSet(filters.FilterSet):
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 = [
"order",
"start",
"end",
"surrounding",
]
class NoteFilterSet(StaticFilterHelpTextMixin, filters.FilterSet):
ids = ModelMultipleChoiceFilter(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment