Esempio n. 1
0
def index():
    today = datetime.date.today()

    # Latest talk query

    subquery = db.session.query(
        tables.Event.city_id,
        func.max(tables.Event.date).label('latest_date'),
    )
    subquery = subquery.group_by(tables.Event.city_id)
    subquery = subquery.subquery()

    query = db.session.query(tables.Event)
    query = query.join(
        subquery,
        and_(
            subquery.c.latest_date == tables.Event.date,
            subquery.c.city_id == tables.Event.city_id,
        ))
    # order: upcoming first, then by distance from today
    jd = func.julianday
    query = query.order_by(
        jd(subquery.c.latest_date) < jd(today),
        func.abs(jd(subquery.c.latest_date) - jd(today)))
    query = query.options(joinedload(tables.Event.city))
    query = query.options(joinedload(tables.Event.venue))
    latest_events = query.all()

    # Video query

    query = db.session.query(tables.TalkLink)
    query = query.filter(
        or_(
            tables.TalkLink.url.startswith('http://www.youtube.com'),
            tables.TalkLink.url.startswith('https://www.youtube.com'),
        ))
    query = query.join(tables.TalkLink.talk)
    query = query.join(tables.Talk.event)
    query = query.options(joinedload(tables.TalkLink.talk))
    query = query.options(joinedload(tables.TalkLink.talk, 'event'))
    query = query.options(joinedload(tables.TalkLink.talk, 'event', 'city'))
    query = query.options(subqueryload(tables.TalkLink.talk, 'talk_speakers'))
    query = query.options(
        joinedload(tables.TalkLink.talk, 'talk_speakers', 'speaker'))
    query = query.order_by(desc(tables.Event.date), tables.Talk.index)
    videos = []
    for link in query[:12]:
        if link.youtube_id:
            videos.append(link)

    calendar = get_calendar(db.session,
                            first_year=today.year,
                            first_month=today.month - 1,
                            num_months=3)

    return render_template('index.html',
                           latest_events=latest_events,
                           today=today,
                           videos=videos,
                           calendar=calendar)
Esempio n. 2
0
def index():
    today = datetime.date.today()

    # Latest talk query

    # order to show meetups in: upcoming first, then by distance from today
    _jd = func.julianday
    order_args = (_jd(tables.Event.date) < _jd(today),
                  func.abs(_jd(tables.Event.date) - _jd(today)))

    # Make a subquery to select the best event from a series
    # (according to the order above)
    subquery = db.session.query(tables.Event.date)
    subquery = subquery.filter(tables.Event.series_slug == tables.Series.slug)
    subquery = subquery.order_by(*order_args)
    subquery = subquery.limit(1).correlate(tables.Series)
    subquery = subquery.subquery()

    # Select all featured series, along with their best event
    query = db.session.query(tables.Event)
    query = query.join(tables.Series, tables.Event.date == subquery)
    query = query.filter(tables.Event.series_slug.in_(FEATURED_SERIES))
    query = query.order_by(*order_args)
    query = query.options(joinedload(tables.Event.series))
    query = query.options(joinedload(tables.Event.venue))
    featured_events = query.all()

    # Video query

    query = db.session.query(tables.TalkLink)
    query = query.filter(or_(
        tables.TalkLink.url.startswith('http://www.youtube.com'),
        tables.TalkLink.url.startswith('https://www.youtube.com'),
    ))
    query = query.join(tables.TalkLink.talk)
    query = query.join(tables.Talk.event)
    query = query.filter(tables.TalkLink.kind == 'video')
    query = query.options(joinedload(tables.TalkLink.talk))
    query = query.options(joinedload(tables.TalkLink.talk, 'event'))
    query = query.options(joinedload(tables.TalkLink.talk, 'event', 'series'))
    query = query.options(subqueryload(tables.TalkLink.talk, 'talk_speakers'))
    query = query.options(joinedload(tables.TalkLink.talk, 'talk_speakers',
                                     'speaker'))
    query = query.order_by(desc(tables.Event.date), tables.Talk.index)
    videos = []
    for link in query[:12]:
        if link.youtube_id:
            videos.append(link)

    calendar = get_calendar(db.session, first_year=today.year,
                            series_slugs=FEATURED_SERIES,
                            first_month=today.month - 1, num_months=3)

    return render_template('index.html', featured_events=featured_events,
                           today=today, videos=videos, calendar=calendar)
Esempio n. 3
0
def index():
    today = datetime.date.today()

    # Latest talk query

    subquery = db.session.query(
        tables.Event.series_slug,
        func.max(tables.Event.date).label('latest_date'),
    )
    subquery = subquery.group_by(tables.Event.series_slug)
    subquery = subquery.subquery()

    query = db.session.query(tables.Event)
    query = query.join(subquery,
                       and_(subquery.c.latest_date == tables.Event.date,
                            subquery.c.series_slug == tables.Event.series_slug,
                            ))
    query = query.filter(tables.Event.series_slug.in_(FEATURED_SERIES))
    # order: upcoming first, then by distance from today
    jd = func.julianday
    query = query.order_by(jd(subquery.c.latest_date) < jd(today),
                           func.abs(jd(subquery.c.latest_date) - jd(today)))
    query = query.options(joinedload(tables.Event.series))
    query = query.options(joinedload(tables.Event.venue))
    featured_events = query.all()

    # Video query

    query = db.session.query(tables.TalkLink)
    query = query.filter(or_(
        tables.TalkLink.url.startswith('http://www.youtube.com'),
        tables.TalkLink.url.startswith('https://www.youtube.com'),
    ))
    query = query.join(tables.TalkLink.talk)
    query = query.join(tables.Talk.event)
    query = query.options(joinedload(tables.TalkLink.talk))
    query = query.options(joinedload(tables.TalkLink.talk, 'event'))
    query = query.options(joinedload(tables.TalkLink.talk, 'event', 'series'))
    query = query.options(subqueryload(tables.TalkLink.talk, 'talk_speakers'))
    query = query.options(joinedload(tables.TalkLink.talk, 'talk_speakers', 'speaker'))
    query = query.order_by(desc(tables.Event.date), tables.Talk.index)
    videos = []
    for link in query[:12]:
        if link.youtube_id:
            videos.append(link)

    calendar = get_calendar(db.session, first_year=today.year,
                            series_slugs=FEATURED_SERIES,
                            first_month=today.month - 1, num_months=3)

    return render_template('index.html', featured_events=featured_events,
                           today=today, videos=videos, calendar=calendar)
Esempio n. 4
0
def calendar(year=None):
    today = datetime.date.today()
    if year is None:
        year = today.year
    try:
        start = datetime.datetime(year, 1, 1)
    except ValueError:
        abort(404)

    calendar = get_calendar(db.session, first_year=start.year,
                            series_slugs=FEATURED_SERIES,
                            first_month=start.month, num_months=12)

    first_year, last_year = min_max_years(db.session.query(tables.Event))

    return render_template('calendar.html', today=today, calendar=calendar,
                           year=year,
                           first_year=first_year, last_year=last_year)
Esempio n. 5
0
def calendar(ctx, date, agenda, year):
    """Show a 3-month calendar of meetups.

    \b
    date: The date around which the calendar is centered. May be:
        - YYYY-MM-DD, YY-MM-DD, YYYY-MM or YY-MM (e.g. 2015-08)
        - MM (e.g. 08): the given month in the current year
        - pN (e.g. p1): N-th last month
        - +N (e.g. +2): N-th next month
        - Omitted: today
        - YYYY: Show the entire year, as with -y
    """
    do_full_year = year
    today = ctx.obj['now'].date()
    db = ctx.obj['db']
    term = ctx.obj['term']

    date_info = cliutil.parse_date(date)
    if 'relative' in date_info:
        year = today.year
        month = today.month + date_info['relative']
    elif 'date_based' in date_info:
        year = date_info.get('year', today.year)
        month = date_info.get('month', today.month)
        if 'month' not in date_info and 'day' not in date_info:
            do_full_year = True
    else:
        raise click.UsageError('Unknown date format')

    if agenda is None:
        agenda = not do_full_year

    if do_full_year:
        first_month = 1
        num_months = 12
    else:
        first_month = month - 1
        num_months = 3

    calendar = get_calendar(db, year, first_month, num_months)
    cliutil.handle_raw_output(ctx, list(calendar.values()))

    render_calendar(term, calendar, today, agenda)
Esempio n. 6
0
def calendar(ctx, date, agenda, year):
    """Show a 3-month calendar of meetups.

    \b
    date: The date around which the calendar is centered. May be:
        - YYYY-MM-DD, YY-MM-DD, YYYY-MM or YY-MM (e.g. 2015-08)
        - MM (e.g. 08): the given month in the current year
        - pN (e.g. p1): N-th last month
        - +N (e.g. +2): N-th next month
        - Omitted: today
        - YYYY: Show the entire year, as with -y
    """
    do_full_year = year
    today = ctx.obj['now'].date()
    db = ctx.obj['db']
    term = ctx.obj['term']

    date_info = cliutil.parse_date(date)
    if 'relative' in date_info:
        year = today.year
        month = today.month + date_info['relative']
    elif 'date_based' in date_info:
        year = date_info.get('year', today.year)
        month = date_info.get('month', today.month)
        if 'month' not in date_info and 'day' not in date_info:
            do_full_year = True
    else:
        raise click.UsageError('Unknown date format')

    if agenda is None:
        agenda = not do_full_year

    if do_full_year:
        first_month = 1
        num_months = 12
    else:
        first_month = month - 1
        num_months = 3

    calendar = get_calendar(db, year, first_month, num_months)
    cliutil.handle_raw_output(ctx, list(calendar.values()))

    render_calendar(term, calendar, today, agenda)
Esempio n. 7
0
def index():
    today = datetime.date.today()

    # Latest talk query

    # order to show meetups in: upcoming first, then by distance from today
    _jd = func.julianday
    order_args = (_jd(tables.Event.date) < _jd(today),
                  func.abs(_jd(tables.Event.date) - _jd(today)))

    # Make a subquery to select the best event from a series
    # (according to the order above)
    subquery = db.session.query(tables.Event.date)
    subquery = subquery.filter(tables.Event.series_slug == tables.Series.slug)
    subquery = subquery.order_by(*order_args)
    subquery = subquery.limit(1).correlate(tables.Series)
    subquery = subquery.subquery()

    # Select all featured series, along with their best event
    query = db.session.query(tables.Event)
    query = query.join(tables.Series, tables.Event.date == subquery)
    query = query.order_by(*order_args)
    query = query.options(joinedload(tables.Event.series))
    query = query.options(joinedload(tables.Event.venue))
    # Only show one event per series
    seen_series = set()
    # Split series into "featured" (recent) and "past" which last took
    # place 6+ months ago.
    featured_events = []
    past_events = []
    for event in query.all():
        if event.series not in seen_series:
            seen_series.add(event.series)
            if event.date + datetime.timedelta(days=31 * 6) >= today:
                featured_events.append(event)
            else:
                past_events.append(event)

    # Video query

    query = db.session.query(tables.TalkLink)
    query = query.filter(
        or_(
            tables.TalkLink.url.startswith('http://www.youtube.com'),
            tables.TalkLink.url.startswith('https://www.youtube.com'),
        ))
    query = query.join(tables.TalkLink.talk)
    query = query.join(tables.Talk.event)
    query = query.filter(tables.TalkLink.kind == 'video')
    query = query.options(joinedload(tables.TalkLink.talk))
    query = query.options(joinedload(tables.TalkLink.talk, 'event'))
    query = query.options(joinedload(tables.TalkLink.talk, 'event', 'series'))
    query = query.options(subqueryload(tables.TalkLink.talk, 'talk_speakers'))
    query = query.options(
        joinedload(tables.TalkLink.talk, 'talk_speakers', 'speaker'))
    query = query.order_by(desc(tables.Event.date), tables.Talk.index)
    videos = []
    for link in query[:12]:
        if link.youtube_id:
            videos.append(link)

    calendar = get_calendar(
        db.session,
        first_year=today.year,
        series_slugs=[e.series.slug for e in featured_events],
        first_month=today.month - 1,
        num_months=3)

    return render_template('index.html',
                           featured_events=featured_events,
                           past_events=past_events,
                           today=today,
                           videos=videos,
                           calendar=calendar)