Skip to content
Snippets Groups Projects

refactor timeslot API filters

Merged Konrad Mohrfeldt requested to merge kmohrf/timeslot-filters into main
1 file
+ 6
14
Compare changes
  • Side-by-side
  • Inline
+ 6
14
@@ -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
Loading