@@ -47,16 +47,17 @@ def get_events(request):
4747 status = "CONFIRMED" , school = "University of Waterloo"
4848 )
4949
50- # Apply default upcoming events filter using EventDates join
50+ # Upcoming events filter: show all live and future events by default
5151 if not dtstart_utc_param :
5252 now = timezone .now ()
53- ninety_minutes_ago = now - timedelta (minutes = 90 )
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)
5753 events_queryset = events_queryset .filter (
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 )
54+ Q (event_dates__dtstart_utc__lte = now , event_dates__dtend_utc__gte = now ) | # Live
55+ Q (event_dates__dtstart_utc__gte = now ) # Upcoming
56+ ).distinct ()
57+ else :
58+ # If dtstart_utc_param is provided, use it as lower bound
59+ events_queryset = events_queryset .filter (
60+ event_dates__dtstart_utc__gte = dtstart_utc_param
6061 ).distinct ()
6162
6263 filterset = EventFilter (request .GET , queryset = events_queryset )
@@ -143,27 +144,23 @@ def get_events(request):
143144 )[: limit + 1 ]
144145 )
145146
146- # Build results with most recent upcoming occurrence dates
147+ # Build results with the next upcoming occurrence date
147148 results = []
148149 now = timezone .now ()
149- ninety_minutes_ago = now - timedelta (minutes = 90 )
150150
151151 for event in events_list :
152- # Get all event dates and filter for upcoming ones
153152 all_dates = list (event .event_dates .all ())
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)
157- upcoming_dates = [
153+ # Find the next upcoming or currently live date
154+ upcoming_or_live_dates = [
158155 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 )
156+ if date .dtstart_utc and (
157+ date .dtstart_utc >= now or
158+ (date .dtstart_utc <= now and date .dtend_utc and date .dtend_utc >= now )
159+ )
161160 ]
162- # Select the most recent upcoming date (first one since they're ordered by dtstart_utc)
163- # If no upcoming dates, fall back to the earliest date overall
164161 selected_date = (
165- upcoming_dates [0 ]
166- if upcoming_dates
162+ upcoming_or_live_dates [0 ]
163+ if upcoming_or_live_dates
167164 else (all_dates [0 ] if all_dates else None )
168165 )
169166
0 commit comments