diff --git a/events/models.py b/events/models.py index 3334ca326..23269884d 100644 --- a/events/models.py +++ b/events/models.py @@ -211,8 +211,15 @@ def previous_time(self): return None @property - def next_or_previous_time(self): - return self.next_time or self.previous_time + def next_or_previous_time(self) -> models.Model: + """Return the next or previous time of the event OR the occurring rule.""" + if next_time := self.next_time: + return next_time + + if previous_time := self.previous_time: + return previous_time + + return self.occurring_rule if hasattr(self, "occurring_rule") else None @property def is_past(self): diff --git a/events/views.py b/events/views.py index 2490626e3..45aa9b3c9 100644 --- a/events/views.py +++ b/events/views.py @@ -40,10 +40,21 @@ def get_context_data(self, **kwargs): class EventHomepage(ListView): """ Main Event Landing Page """ - template_name = 'events/event_list.html' + template_name = "events/event_list.html" - def get_queryset(self): - return Event.objects.for_datetime(timezone.now()).order_by('occurring_rule__dt_start') + def get_queryset(self) -> Event: + """Queryset to return all events, ordered by START date.""" + return Event.objects.all().order_by("-occurring_rule__dt_start") + + def get_context_data(self, **kwargs: dict) -> dict: + """Add more ctx, specifically events that are happening now, just misse, and upcoming.""" + context = super().get_context_data(**kwargs) + context["events_just_missed"] = Event.objects.until_datetime(timezone.now())[:2] + context["upcoming_events"] = Event.objects.for_datetime(timezone.now()) + context["events_now"] = Event.objects.filter( + occurring_rule__dt_start__lte=timezone.now(), + occurring_rule__dt_end__gte=timezone.now())[:2] + return context class EventDetail(DetailView): @@ -68,11 +79,13 @@ def get_context_data(self, **kwargs): class EventList(EventListBase): def get_queryset(self): - return Event.objects.for_datetime(timezone.now()).filter(calendar__slug=self.kwargs['calendar_slug']).order_by('occurring_rule__dt_start') + return Event.objects.for_datetime(timezone.now()).filter(calendar__slug=self.kwargs['calendar_slug']).order_by( + 'occurring_rule__dt_start') def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context['events_today'] = Event.objects.until_datetime(timezone.now()).filter(calendar__slug=self.kwargs['calendar_slug'])[:2] + context['events_today'] = Event.objects.until_datetime(timezone.now()).filter( + calendar__slug=self.kwargs['calendar_slug'])[:2] context['calendar'] = get_object_or_404(Calendar, slug=self.kwargs['calendar_slug']) return context diff --git a/templates/events/event_list.html b/templates/events/event_list.html index bbfb764d2..f411baeed 100644 --- a/templates/events/event_list.html +++ b/templates/events/event_list.html @@ -8,73 +8,110 @@ {% block header_content %} {% if featured %} -
{{ featured.description.rendered|striptags|truncatewords:"60" }} Read more
-+ +
+{{ featured.description.rendered|striptags|truncatewords:"60" }} Read + more
+