Skip to content

Commit

Permalink
fix: display active events, fix time not displaying for some events
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobCoffee committed Sep 13, 2024
1 parent ee0a7da commit d0407c9
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 50 deletions.
11 changes: 9 additions & 2 deletions events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
23 changes: 18 additions & 5 deletions events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

Expand Down
123 changes: 80 additions & 43 deletions templates/events/event_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,73 +8,110 @@

{% block header_content %}
{% if featured %}
<div class="featured-event">
<div class="featured-event">

<h2 class="welcome-message">Featured Python Event</h2>
<h2 class="welcome-message">Featured Python Event</h2>

<h1 class="call-to-action">{{ featured.title|striptags }}</h1>
<h1 class="call-to-action">{{ featured.title|striptags }}</h1>

<p class="event-date"><time datetime="{{ featured.next_datetime.dt_start|date:'c' }}">
{{ featured.next_datetime.dt_start|date:"l, F d, Y" }}
</time></p>
<p class="excerpt">{{ featured.description.rendered|striptags|truncatewords:"60" }} <a class="readmore" href="{{ featured.get_absolute_url }}">Read more</a></p>
</div>
<p class="event-date">
<time datetime="{{ featured.next_datetime.dt_start|date:'c' }}">
{{ featured.next_datetime.dt_start|date:"l, F d, Y" }}
</time>
</p>
<p class="excerpt">{{ featured.description.rendered|striptags|truncatewords:"60" }} <a class="readmore"
href="{{ featured.get_absolute_url }}">Read
more</a></p>
</div>
{% endif %}
{% endblock header_content %}


{# Based on python/events.html #}

{% block content %}

{% if calendar %}
{% if calendar %}
<header class="article-header">
<h3>from the {{ calendar.name }}</h3>
</header>
{% endif %}
{% endif %}

<div class="most-recent-events">
<div class="most-recent-events">
{% if events_now %}
<div class="shrubbery">
<h2 class="widget-title"><span aria-hidden="true" class="icon-calendar"></span>Upcoming Events</h2>
{% if page_obj.has_next %}
<p class="give-me-more"><a href="?page={{ page_obj.next_page_number }}" title="More Events">More</a></p>
{% endif %}
<h2 class="widget-title"><span aria-hidden="true" class="icon-calendar"></span>Happening Now</h2>
<ul class="list-recent-events menu">
{% for object in object_list %}
{% for object in events_now %}
<li>
<h3 class="event-title"><a
href="{{ object.get_absolute_url }}">{{ object.title|striptags }}</a></h3>
<p>
{% with object.occurring_rule as next_time %}
{% include "events/includes/time_tag.html" %}
{% endwith %}

{% if object.venue %}
<span class="event-location">{% if object.venue.url %}
<a href="{{ object.venue.url }}">{% endif %}{{ object.venue.name }}
{% if object.venue.url %}</a>{% endif %}{% if object.venue.address %},
{{ object.venue.address }}{% endif %}</span>
{% endif %}
</p>
</li>
{% endfor %}
</ul>
</div>
{% endif %}

<div class="shrubbery">
<h2 class="widget-title"><span aria-hidden="true" class="icon-calendar"></span>Upcoming Events</h2>
{% if page_obj.has_next %}
<p class="give-me-more"><a href="?page={{ page_obj.next_page_number }}" title="More Events">More</a></p>
{% endif %}
<ul class="list-recent-events menu">
{% for object in upcoming_events %}
<li>
<h3 class="event-title"><a href="{{ object.get_absolute_url }}">{{ object.title|striptags }}</a></h3>
<h3 class="event-title"><a href="{{ object.get_absolute_url }}">{{ object.title|striptags }}</a>
</h3>
<p>
{% with object.next_time as next_time %}
{% include "events/includes/time_tag.html" %}
{% include "events/includes/time_tag.html" %}
{% endwith %}

{% if object.venue %}
<span class="event-location">{% if object.venue.url %}<a href="{{ object.venue.url }}">{% endif %}{{ object.venue.name }}{% if object.venue.url %}</a>{% endif %}{% if object.venue.address %}, {{ object.venue.address }}{% endif %}</span>
<span class="event-location">{% if object.venue.url %}
<a href="{{ object.venue.url }}">{% endif %}{{ object.venue.name }}
{% if object.venue.url %}</a>{% endif %}{% if object.venue.address %},
{{ object.venue.address }}{% endif %}</span>
{% endif %}
</p>
</li>
{% endfor %}
</ul>
</div>

{% if events_today %}
<h3 class="widget-title just-missed">You just missed...</h3>
<ul class="list-recent-events menu">
{% for object in events_today %}
<li>
<h3 class="event-title"><a href="{{ object.get_absolute_url }}">{{ object.title|striptags }}</a></h3>
<p>
{% with object.previous_time as next_time %}
{% include "events/includes/time_tag.html" %}
{% endwith %}

{% if object.venue %}
<span class="event-location">{% if object.venue.url %}<a href="{{ object.venue.url }}">{% endif %}{{ object.venue.name }}{% if object.venue.url %}</a>{% endif %}{% if object.venue.address %}, {{ object.venue.address }}{% endif %}</span>
{% endif %}
</p>
</li>
{% endfor %}
</ul>
{% endif %}
</div>

{% if events_just_missed %}
<div class="shrubbery">
<h3 class="widget-title just-missed">You just missed...</h3>
<ul class="list-recent-events menu">
{% for object in events_just_missed %}
<li>
<h3 class="event-title"><a
href="{{ object.get_absolute_url }}">{{ object.title|striptags }}</a></h3>
<p>
{% with object.previous_time as next_time %}
{% include "events/includes/time_tag.html" %}
{% endwith %}

{% if object.venue %}
<span class="event-location">{% if object.venue.url %}
<a href="{{ object.venue.url }}">{% endif %}{{ object.venue.name }}
{% if object.venue.url %}</a>{% endif %}{% if object.venue.address %},
{{ object.venue.address }}{% endif %}</span>
{% endif %}
</p>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
</div>
{% endblock content %}

0 comments on commit d0407c9

Please sign in to comment.