예제 #1
0
파일: schema.py 프로젝트: neithere/orgtool
    def update_dates_rrule(self, last_event=None):
        # NOTE: we are not trying to be too smart here, just some basic guesses
        # apart from the straightforward logic. Facts will *not* fit the plans
        # most of the time.
        if self.dates_rrule_text:

            # FIXME HACK
            if self.dates_rrule_text.startswith('once '):
                rrule_text = self.dates_rrule_text.replace('once ', 'every ')
            else:
                rrule_text = self.dates_rrule_text

            #print 'text defined'

            # looks like rrule will pick now() if valid_since is None even if
            # after(x) is given, so we pass the first event date in this case
            since = self.valid_since or (
                self.events.order_by('date_time')[0].date_time if self.events else None)
            self.dates_rrule = informal_rrule(rrule_text,
                since = since,
                until = self.valid_until
            )
            #print 'rrule created'
            if not last_event and self.events:
                #print 'no explicit last event but there are some'
                # XXX NOTE: assumed that payments are sorted by date DESC (most
                # recent on top):
                last_event = self.events[0]
            if last_event:
                #print 'got explicit last event', last_event
                self.next_date_time = self.dates_rrule.after(last_event.date_time)
            elif self.skip_past_events:
                now = datetime.datetime.utcnow()  # or better yesterday?
                self.next_date_time = self.dates_rrule.after(now)
            else:
                #print 'no last event at all, picking 1st rrule event'
                try:
                    self.next_date_time = self.dates_rrule[0]
                except IndexError:
                    self.next_date_time = None

            # FIXME HACK
            if self.dates_rrule_text.startswith('once '):
                self.dates_rrule = None
        else:
            #print 'no rrule text'
            self.dates_rrule = self.next_date_time = None
            if self.valid_until:
                self.next_date_time = datetime.datetime.combine(
                    self.valid_until, datetime.time())
예제 #2
0
파일: schema.py 프로젝트: neithere/orgtool
def informal_rrule(*args, **kwargs):
    "A wrapper for informal_rrule that does lazy import"
    from orgtool.utils.dates import informal_rrule
    return informal_rrule(*args, **kwargs)