@@ -51,9 +51,12 @@ def get_events(request):
5151 if not dtstart_utc_param :
5252 now = timezone .now ()
5353 ninety_minutes_ago = now - timedelta (minutes = 90 )
54- # Filter events that have at least one upcoming date
54+ # Filter events that are either:
55+ # 1. Have no end time and started within last 90 minutes
56+ # 2. Have end time and are currently happening (between start and end)
5557 events_queryset = events_queryset .filter (
56- event_dates__dtstart_utc__gte = ninety_minutes_ago
58+ Q (event_dates__dtend_utc__isnull = True , event_dates__dtstart_utc__gte = ninety_minutes_ago )
59+ | Q (event_dates__dtend_utc__isnull = False , event_dates__dtstart_utc__lte = now , event_dates__dtend_utc__gte = now )
5760 ).distinct ()
5861
5962 filterset = EventFilter (request .GET , queryset = events_queryset )
@@ -148,9 +151,13 @@ def get_events(request):
148151 for event in events_list :
149152 # Get all event dates and filter for upcoming ones
150153 all_dates = list (event .event_dates .all ())
151- # Filter to only upcoming dates (>= ninety_minutes_ago to match the filter logic)
154+ # Filter to only upcoming/live dates matching the query logic:
155+ # 1. No end time and started within last 90 minutes
156+ # 2. Has end time and currently happening (between start and end)
152157 upcoming_dates = [
153- date for date in all_dates if date .dtstart_utc >= ninety_minutes_ago
158+ date for date in all_dates
159+ if (date .dtend_utc is None and date .dtstart_utc >= ninety_minutes_ago )
160+ or (date .dtend_utc is not None and date .dtstart_utc <= now and date .dtend_utc >= now )
154161 ]
155162 # Select the most recent upcoming date (first one since they're ordered by dtstart_utc)
156163 # If no upcoming dates, fall back to the earliest date overall
0 commit comments