diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/reservations.py b/SAS/TMSS/backend/src/tmss/tmssapp/reservations.py index 3cc5cd8794191a8e2fc9ddd064e54dc120b97f42..25909b98bab8c01e7340d1b32caa69ffa86dd307 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/reservations.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/reservations.py @@ -6,8 +6,15 @@ def get_active_station_reservations_in_timewindow(lower_bound, upper_bound): Retrieve a list of all active stations reservations, which are reserved between a timewindow """ lst_active_station_reservations = [] - for res in models.Reservation.objects.filter(start_time__lt=upper_bound, stop_time__gt=lower_bound).values('specifications_doc'): - lst_active_station_reservations += res["specifications_doc"]["resources"]["stations"] - for res in models.Reservation.objects.filter(start_time__lt=upper_bound, stop_time=None).values('specifications_doc'): + if upper_bound is None: + queryset = models.Reservation.objects.filter(start_time__lt=upper_bound) + else: + queryset = models.Reservation.objects.all() + + for res in queryset.filter(stop_time=None).values('specifications_doc'): lst_active_station_reservations += res["specifications_doc"]["resources"]["stations"] + + if lower_bound is not None: + for res in queryset.filter(stop_time__gt=lower_bound).values('specifications_doc'): + lst_active_station_reservations += res["specifications_doc"]["resources"]["stations"] return list(set(lst_active_station_reservations))