django-scheduler
django-scheduler copied to clipboard
Should a Period's get_persisted_occurrences be limited to their timeframe?
Right now, Periods return all persisted Occurrences, even if they're outside the time frame of the period:
def get_persisted_occurrences(self):
if hasattr(self, '_persisted_occurrenes'):
return self._persisted_occurrences
else:
self._persisted_occurrences = Occurrence.objects.filter(event__in=self.events)
return self._persisted_occurrences
This was unexpected to me, as I assumed that get_persisted_occurrences would only return Occurrences within the period. For example, I thought that Day(events).get_persisted_occurrences()
would only return persisted Occurrences from today, even if the events had been recurring for longer than that.
In my own project, I'm doing
today = Day(events, tzinfo=get_current_timezone())
today.get_persisted_occurrences().filter(start__gte=today.start,
end__lt=today.end)
However, I think the secondary filter should be part of what get_persisted_occurrences() returns.
Thumb this up, i had to monkey patch this to work properly, this is not the logical behavior. Persisted occurreces of period should be inside that period!