Skip to content

Commit

Permalink
Fixed occurrence generation in day views for events with multiple days
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Lorenz committed Sep 5, 2016
1 parent 9e6b6af commit cabe69e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 7 additions & 4 deletions calendarium/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,14 @@ def _get_occurrence_gen(self, start, end):
start - length, self.end)

# chosing the first item from the generator to initiate
occ_start = next(occ_start_gen)
while not end or (end and occ_start <= end):
occ_end = occ_start + length
yield self._create_occurrence(occ_start, occ_end)
try:
occ_start = next(occ_start_gen)
while not end or (end and occ_start <= end):
occ_end = occ_start + length
yield self._create_occurrence(occ_start, occ_end)
occ_start = next(occ_start_gen)
except StopIteration:
pass

def get_occurrences(self, start, end=None):
"""Returns all occurrences from start to end."""
Expand Down
8 changes: 7 additions & 1 deletion calendarium/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,13 @@ def get_context_data(self, **kwargs):
ctx = self.get_category_context()
occurrences = Event.objects.get_occurrences(
self.date, self.date, ctx.get('current_category'))
ctx.update({'date': self.date, 'occurrences': occurrences})
ctx.update({
'date': self.date,
'occurrences': filter(
lambda occ, date=self.date: occ.start.replace(
hour=0, minute=0, second=0, microsecond=0) == self.date,
occurrences),
})
return ctx


Expand Down

0 comments on commit cabe69e

Please sign in to comment.