Ejemplo n.º 1
0
def get_upcoming_dates(now):
    settings = get_settings()
    if not settings or not settings.send_reminders or not settings.begin_date:
        raise StopIteration()

    if settings.get_interval() < 0:
        yield now, "Current newsletter"
        raise StopIteration()

    to_yield = 7
    current = settings.begin_date

    while to_yield > 0:
        if current >= now - datetime.timedelta(2 * settings.get_interval()):
            diff = current - now
            days = abs(diff.days) % 7
            weeks = abs(diff.days) / 7

            if diff.days == 0:
                yield current, _("now")
            elif diff.days > 0:
                if weeks == 0:
                    yield current, _("%(days)s days") % locals()
                else:
                    yield current, _("in %(weeks)s weeks") % locals()
            else:
                if weeks == 0:
                    yield current, _("%(days)s days ago") % locals()
                else:
                    yield current, _("%(weeks)s weeks ago") % locals()
            to_yield -= 1
        current += datetime.timedelta(settings.get_interval())
Ejemplo n.º 2
0
def get_upcoming_dates(now):
    settings = get_settings()
    if not settings or not settings.send_reminders or not settings.begin_date:
        raise StopIteration()

    if settings.get_interval() < 0:
        yield now, "Current newsletter"
        raise StopIteration()

    to_yield = 7
    current = settings.begin_date

    while to_yield > 0:
        if current >= now - datetime.timedelta(2 * settings.get_interval()):
            diff = current - now
            days = abs(diff.days) % 7
            weeks = abs(diff.days) / 7

            if diff.days == 0:
                yield current, _("now")
            elif diff.days > 0:
                if weeks == 0:
                    yield current, _("%(days)s days") % locals()
                else:
                    yield current, _("in %(weeks)s weeks") % locals()
            else:
                if weeks == 0:
                    yield current, _("%(days)s days ago") % locals()
                else:
                    yield current, _("%(weeks)s weeks ago") % locals()
            to_yield -= 1
        current += datetime.timedelta(settings.get_interval())
Ejemplo n.º 3
0
def get_prev_reminder_date(now, published=True):
    """Returns the date of the previous reminder or None if there's no
    such date"""
    function = 'def get_prev_reminder_data'
    logger.debug(function)
    settings = get_settings()

    if not settings or not settings.send_reminders or not settings.begin_date or now < settings.begin_date:
        logger.debug('%s - not settings' % function )
        return None

    if settings.interval == NO_INTERVAL:
        logger.debug('%s - settings: NO_INTERNAL' % function )
        qs = NewsLetter.objects.filter(date__lte=now).exclude(date__gt=now).order_by("-date")
        if published:
            qs = qs.filter(published=published)
        qs = list(qs)
        if len(qs) == 0:
            return None
        return qs[0].date

    current = settings.begin_date
    prev = settings.begin_date

    while True:
        if current >= now:
            return prev
        prev = current
        current += datetime.timedelta(settings.get_interval())
Ejemplo n.º 4
0
def get_prev_reminder_date(now, published=True):
    """Returns the date of the previous reminder or None if there's no
    such date"""
    function = 'def get_prev_reminder_data'
    logger.debug(function)
    settings = get_settings()

    if not settings or not settings.send_reminders or not settings.begin_date or now < settings.begin_date:
        logger.debug('%s - not settings' % function)
        return None

    if settings.interval == NO_INTERVAL:
        logger.debug('%s - settings: NO_INTERNAL' % function)
        qs = NewsLetter.objects.filter(date__lte=now).exclude(
            date__gt=now).order_by("-date")
        if published:
            qs = qs.filter(published=published)
        qs = list(qs)
        if len(qs) == 0:
            return None
        return qs[0].date

    current = settings.begin_date
    prev = settings.begin_date

    while True:
        if current >= now:
            return prev
        prev = current
        current += datetime.timedelta(settings.get_interval())