Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Fix infinite loop and don't show list if no events can be found (dat …
Browse files Browse the repository at this point in the history
…3am logic).
  • Loading branch information
Greg Turner committed Dec 7, 2016
1 parent a867245 commit 90e7eba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
7 changes: 3 additions & 4 deletions icekit_events/plugins/todays_occurrences/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _calculate(self):
self.day = today
self.qs = Occurrence.objects.none()

stop_days = 0 if self.fall_back_to_next_day else 365
stop_day = self.day+timedelta(days=7) if self.fall_back_to_next_day else self.day

initial_qs = Occurrence.objects.visible().distinct()
if self.types_to_show.count():
Expand All @@ -36,16 +36,15 @@ def _calculate(self):

# starting from today, see if there are any occurrences.
# Stop when we find some, or stop_days later.
while self.day <= self.day + timedelta(days=stop_days):
while self.day < stop_day:
qs = initial_qs.available_on_day(self.day)
if self.day == today and not self.include_finished:
qs = qs.upcoming()

if qs.count(): # found some!
self.qs = qs
break
else:
self.day += timedelta(days=1)
self.day += timedelta(days=1)


def get_occurrences(self):
Expand Down
30 changes: 16 additions & 14 deletions icekit_events/templates/plugins/todays_occurrences/default.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{% load humanize %}

<h3 class="primary-divider">
<span class="content-max-width">
{% if instance.title %}
{{ instance.title }} {{ instance.get_date|naturalday }}
{% else %}
{{ instance.get_date|naturalday|title }}
{% endif %}
</span>
</h3>
{% with instance.get_occurrences as occs %}
{% if occs %}
<h3 class="primary-divider">
<span class="content-max-width">
{% if instance.title %}
{{ instance.title }} {{ instance.get_date|naturalday }}
{% else %}
{{ instance.get_date|naturalday|title }}
{% endif %}
</span>
</h3>



{% for occ in instance.get_occurrences %}
{% include "plugins/link/_whatson_link.html" with event=occ.event %}
{% endfor %}
{% for occ in occs %}
{% include "plugins/link/_whatson_link.html" with event=occ.event %}
{% endfor %}
{% endif %}
{% endwith %}

0 comments on commit 90e7eba

Please sign in to comment.