Exemplo n.º 1
0
def comic_queue_do(request):
    # TODO this would be easier with a real validator.
    weekdays = []
    for wd in request.POST.getall('weekday'):
        if wd in '0123456':
            weekdays.append(int(wd))

    queued = (
        session.query(ComicPage)
        .join(ComicPage.chapter)
        .filter(ComicPage.is_queued)
        .order_by(ComicPage.order.asc())
        .all()
    )

    new_dates = _generate_queue_dates(weekdays, start=get_current_publication_date(XXX_HARDCODED_TIMEZONE))
    for page, new_date in zip(queued, new_dates):
        page.date_published = datetime.combine(
            new_date, time()).replace(tzinfo=pytz.utc)
        page.timezone = XXX_HARDCODED_TIMEZONE.zone

    comic.config_queue = ''.join(str(wd) for wd in sorted(weekdays))

    # TODO flash message?
    return HTTPSeeOther(location=request.route_url('comic.admin', comic))
Exemplo n.º 2
0
def comic_admin(request):
    # Figure out the starting date for the calendar.  We want to show the
    # previous four weeks, and start at the beginning of the week.
    today = get_current_publication_date(XXX_HARDCODED_TIMEZONE)
    weekday_offset = (today.weekday() - 6) % -7
    start = today + timedelta(days=weekday_offset - 7 * 4)

    # Grab "recent" pages -- any posted in the past two weeks OR in the future.
    recent_pages = (
        session.query(ComicPage)
        .join(ComicPage.chapter)
        .filter(ComicPage.date_published >= start.astimezone(pytz.utc))
        .order_by(ComicPage.date_published.desc())
        .all()
    )

    last_queued, queue_next_date = _get_last_queued_date()
    num_queued = sum(1 for page in recent_pages if page.is_queued)

    day_to_page = {page.date_published.date(): page for page in recent_pages}

    chapters = (
        session.query(ComicChapter)
        .order_by(ComicChapter.order.asc())
        .options(
            joinedload('children')
        )
        .all()
    )

    # Express calendar in dates.  Go at least four weeks into the future, OR
    # one week beyond the last queued comic (for some padding).
    calendar_start = start.date()
    calendar_start -= timedelta(days=calendar_start.isoweekday() % 7)
    calendar_end = today.date() + timedelta(days=7 * 4)
    if day_to_page:
        calendar_end = max(calendar_end, max(day_to_page) + timedelta(days=7))

    # TODO really really really need to move configuration out of comics.  this
    # was clever but not clever enough.
    comic = session.query(Comic).order_by(Comic.id.asc()).first()

    return dict(
        comic=comic,
        chapters=chapters,
        num_queued=num_queued,
        last_queued=last_queued,
        queue_next_date=queue_next_date,

        day_to_page=day_to_page,
        calendar_start=calendar_start,
        calendar_end=calendar_end,
    )
Exemplo n.º 3
0
def _get_last_queued_date():
    queued_q = session.query(ComicPage).join(ComicPage.chapter).filter(ComicPage.is_queued)

    last_queued = queued_q.order_by(ComicPage.date_published.desc()).first()

    if last_queued:
        queue_end_date = last_queued.date_published
    else:
        queue_end_date = datetime.combine(
            get_current_publication_date(XXX_HARDCODED_TIMEZONE).astimezone(pytz.utc), time()
        )
    if queue_end_date == END_OF_TIME:
        queue_next_date = None
    else:
        weekdays = [int(wd) for wd in XXX_HARDCODED_QUEUE]
        queue_next_date = next(_generate_queue_dates(weekdays, start=queue_end_date))

    return last_queued, queue_next_date
Exemplo n.º 4
0
def comic_admin(request):
    # Figure out the starting date for the calendar.  We want to show the
    # previous four weeks, and start at the beginning of the week.
    today = get_current_publication_date(XXX_HARDCODED_TIMEZONE)
    weekday_offset = (today.weekday() - 6) % -7
    start = today + timedelta(days=weekday_offset - 7 * 4)

    # Grab "recent" pages -- any posted in the past two weeks OR in the future.
    recent_pages = (session.query(ComicPage).join(ComicPage.chapter).filter(
        ComicPage.date_published >= start.astimezone(pytz.utc)).order_by(
            ComicPage.date_published.desc()).all())

    last_queued, queue_next_date = _get_last_queued_date()
    num_queued = sum(1 for page in recent_pages if page.is_queued)

    day_to_page = {page.date_published.date(): page for page in recent_pages}

    chapters = (session.query(ComicChapter).order_by(
        ComicChapter.order.asc()).options(joinedload('children')).all())

    # Express calendar in dates.  Go at least four weeks into the future, OR
    # one week beyond the last queued comic (for some padding).
    calendar_start = start.date()
    calendar_start -= timedelta(days=calendar_start.isoweekday() % 7)
    calendar_end = today.date() + timedelta(days=7 * 4)
    if day_to_page:
        calendar_end = max(calendar_end, max(day_to_page) + timedelta(days=7))

    # TODO really really really need to move configuration out of comics.  this
    # was clever but not clever enough.
    comic = session.query(Comic).order_by(Comic.id.asc()).first()

    return dict(
        comic=comic,
        chapters=chapters,
        num_queued=num_queued,
        last_queued=last_queued,
        queue_next_date=queue_next_date,
        day_to_page=day_to_page,
        calendar_start=calendar_start,
        calendar_end=calendar_end,
    )
Exemplo n.º 5
0
def comic_queue_do(request):
    # TODO this would be easier with a real validator.
    weekdays = []
    for wd in request.POST.getall('weekday'):
        if wd in '0123456':
            weekdays.append(int(wd))

    queued = (session.query(ComicPage).join(ComicPage.chapter).filter(
        ComicPage.is_queued).order_by(ComicPage.order.asc()).all())

    new_dates = _generate_queue_dates(
        weekdays, start=get_current_publication_date(XXX_HARDCODED_TIMEZONE))
    for page, new_date in zip(queued, new_dates):
        page.date_published = datetime.combine(new_date,
                                               time()).replace(tzinfo=pytz.utc)
        page.timezone = XXX_HARDCODED_TIMEZONE.zone

    comic.config_queue = ''.join(str(wd) for wd in sorted(weekdays))

    # TODO flash message?
    return HTTPSeeOther(location=request.route_url('comic.admin', comic))
Exemplo n.º 6
0
def _get_last_queued_date():
    queued_q = (session.query(ComicPage).join(ComicPage.chapter).filter(
        ComicPage.is_queued))

    last_queued = queued_q.order_by(ComicPage.date_published.desc()).first()

    if last_queued:
        queue_end_date = last_queued.date_published
    else:
        queue_end_date = datetime.combine(
            get_current_publication_date(XXX_HARDCODED_TIMEZONE).astimezone(
                pytz.utc),
            time(),
        )
    if queue_end_date == END_OF_TIME:
        queue_next_date = None
    else:
        weekdays = [int(wd) for wd in XXX_HARDCODED_QUEUE]
        queue_next_date = next(
            _generate_queue_dates(weekdays, start=queue_end_date))

    return last_queued, queue_next_date