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

refactor: rename start and end timeslot filters and support datetimes

These filters now support datetimes as well as dates and their naming
now reflects what they are querying.
parent 5c9a0de5
No related branches found
No related tags found
1 merge request!28refactor timeslot API filters
......@@ -184,20 +184,20 @@ class TimeSlotFilterSet(filters.FilterSet):
"If specified without a datetime value the current date and time is assumed."
),
)
start = filters.DateFilter(
method="filter_start",
starts_after = filters.DateTimeFilter(
field_name="start",
lookup_expr="gte",
help_text="Only returns timeslots that start at or after the specified datetime.",
)
end = filters.DateFilter(
method="filter_end",
ends_before = filters.DateTimeFilter(
field_name="end",
lookup_expr="lt",
help_text="Only returns timeslots that end before the specified datetime.",
)
schedule_ids = IntegerInFilter(
field_name="schedule",
help_text="Return only timeslots that belong to the specified schedule(s).",
)
show_ids = IntegerInFilter(
field_name="schedule__show",
help_text="Return only timeslots that belong to the specified show(s).",
......@@ -217,14 +217,6 @@ class TimeSlotFilterSet(filters.FilterSet):
relevant_timeslot_ids = list(nearest_timeslots_in_future) + list(nearest_timeslots_in_past)
return queryset.filter(id__in=relevant_timeslot_ids)
def filter_start(self, queryset: QuerySet, name: str, value: datetime.date):
start = timezone.make_aware(datetime.datetime.combine(value, datetime.time.min))
return queryset.filter(start__gte=start)
def filter_end(self, queryset: QuerySet, name: str, value: datetime.date):
end = timezone.make_aware(datetime.datetime.combine(value, datetime.time.max))
return queryset.filter(end__lte=end)
def filter_queryset(self, queryset):
queryset = super().filter_queryset(queryset)
# This is for backwards compatibility as the surrounding-filter was formerly implemented
......
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