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

Commit

Permalink
Use get_occurrences() for display purposes, since it falls back to th…
Browse files Browse the repository at this point in the history
…e occurrences of the part_of event if no more specific occurrences are given.
  • Loading branch information
Greg Turner committed Nov 23, 2016
1 parent f2bd4e2 commit 3e399a2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
20 changes: 15 additions & 5 deletions icekit_events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,22 @@ def clone_event_relationships(self, dst_obj):
generator.event = dst_obj
generator.save()

def get_occurrences(self):
"""
:return: My occurrences, or those of my part_of event
"""
if self.occurrences.count():
return self.occurrences
elif self.part_of:
return self.part_of.get_occurrences()
return self.occurrences # will be empty, but at least queryable

def get_occurrences_range(self):
"""
Return the first and last chronological `Occurrence` for this event.
"""
first = self.occurrences.order_by('start').first()
last = self.occurrences.order_by('-end').first()
first = self.get_occurrences().order_by('start').first()
last = self.get_occurrences().order_by('-end').first()
return (first, last)

def get_occurrences_by_day(self):
Expand All @@ -447,7 +457,7 @@ def get_occurrences_by_day(self):
"""
result = OrderedDict()

for occ in self.occurrences.order_by('start'):
for occ in self.get_occurrences().order_by('start'):
result.setdefault(occ.local_start.date, []).append(occ)

return result.items()
Expand All @@ -458,7 +468,7 @@ def start_dates_set(self):
:return: a sorted set of all the different dates that this event
happens on.
"""
occurrences = self.occurrences.filter(
occurrences = self.get_occurrences().filter(
is_cancelled=False
)
dates = set([o.local_start.date() for o in occurrences])
Expand All @@ -470,7 +480,7 @@ def start_times_set(self):
:return: a sorted set of all the different times that this event
happens on.
"""
occurrences = self.occurrences.filter(
occurrences = self.get_occurrences().filter(
is_all_day=False, is_cancelled=False
)
times = set([o.local_start.time() for o in occurrences])
Expand Down
2 changes: 1 addition & 1 deletion icekit_events/templatetags/events_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def timesf(times_list, format=None):
@register.filter
def times_range(event, format=None):
sts = timesf(event.start_times_set(), format=format)
all_days = event.occurrences.filter(is_all_day=True)
all_days = event.get_occurrences().filter(is_all_day=True)
if all_days:
sts = ["all day"] + sts

Expand Down
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

0 comments on commit 3e399a2

Please sign in to comment.