(self, instance, start_date=None)
If start_date is None, we set it automatically ensuring that
        self.next_event_due does not get set in the past for the first
        event.
If start_date is None, we set it automatically ensuring that
        self.next_event_due does not get set in the past for the first
        event.
If start_date is None we set it automatically ensuring that self . next_event_due does not get set in the past for the first event .
def set_first_event_due_timestamp(self, instance, start_date=None):
        """
        If start_date is None, we set it automatically ensuring that
        self.next_event_due does not get set in the past for the first
        event.
        """
        if start_date:
            instance.start_date = start_date
        else:
            instance.start_date = instance.get_today_for_recipient(self)

        self.set_next_event_due_timestamp(instance)

        # If there was no specific start date for the schedule, we
        # start it today. But that can cause us to put the first event
        # in the past if it has already passed for the day. So if that
        # happens, push the schedule out by 1 day for daily schedules,
        # 1 week for weekly schedules, or 1 month for monthly schedules.
        if (
            not start_date and
            instance.next_event_due < util.utcnow()
        ):
            if self.is_monthly:
                # Monthly
                new_start_date = instance.start_date + relativedelta(months=1)
                instance.start_date = date(new_start_date.year, new_start_date.month, 1)
                # Current event and schedule iteration might be updated
                # in the call to set_next_event_due_timestamp, so reset them
                instance.current_event_num = 0
                instance.schedule_iteration_num = 1
            elif self.start_day_of_week == self.ANY_DAY:
                # Daily
                instance.start_date += timedelta(days=1)
            else:
                # Weekly
                instance.start_date += timedelta(days=7)

            self.set_next_event_due_timestamp(instance)
def set_first_event_due_timestamp ( self , instance , start_date = None ) : if start_date : instance . start_date = start_date else : instance . start_date = instance . get_today_for_recipient ( self ) self . set_next_event_due_timestamp ( instance ) # If there was no specific start date for the schedule, we # start it today. But that can cause us to put the first event # in the past if it has already passed for the day. So if that # happens, push the schedule out by 1 day for daily schedules, # 1 week for weekly schedules, or 1 month for monthly schedules. if ( not start_date and instance . next_event_due < util . utcnow ( ) ) : if self . is_monthly : # Monthly new_start_date = instance . start_date + relativedelta ( months = 1 ) instance . start_date = date ( new_start_date . year , new_start_date . month , 1 ) # Current event and schedule iteration might be updated # in the call to set_next_event_due_timestamp, so reset them instance . current_event_num = 0 instance . schedule_iteration_num = 1 elif self . start_day_of_week == self . ANY_DAY : # Daily instance . start_date += timedelta ( days = 1 ) else : # Weekly instance . start_date += timedelta ( days = 7 ) self . set_next_event_due_timestamp ( instance )