Example #1
0
def index():
    query = Event.query() \
        .options(subqueryload('actor')) \
        .options(subqueryload('user')) \
        .options(subqueryload('club')) \
        .outerjoin(Event.flight) \
        .options(contains_eager(Event.flight)) \
        .filter(or_(Event.flight == None, Flight.is_rankable())) \
        .order_by(Event.time.desc())

    query = _filter_query(query, request.args)

    page = request.args.get('page', type=int, default=1)
    per_page = request.args.get('per_page', type=int, default=50)

    events = query.limit(per_page).offset((page - 1) * per_page).all()
    events_count = len(events)

    if request.args.get('grouped', True, type=str_to_bool):
        events = group_events(events)

    template_vars = dict(events=events, types=Event.Type)

    if page > 1:
        template_vars['prev_page'] = page - 1
    if events_count == per_page:
        template_vars['next_page'] = page + 1

    return render_template('timeline/list.jinja', **template_vars)
Example #2
0
def _list():
    query = (Event.query().options(subqueryload("user")).options(
        subqueryload("club")).outerjoin(Event.flight).options(
            contains_eager(Event.flight)).filter(
                or_(Event.flight == None,
                    Flight.is_rankable())).order_by(Event.time.desc()))

    query = _filter_query(query, request.args)

    page = request.args.get("page", type=int, default=1)
    per_page = request.args.get("per_page", type=int, default=50)

    events = query.limit(per_page).offset((page - 1) * per_page).all()

    return jsonify(events=([convert_event(event) for event in events]))
Example #3
0
def _list():
    query = Event.query() \
        .options(subqueryload('actor')) \
        .options(subqueryload('user')) \
        .options(subqueryload('club')) \
        .outerjoin(Event.flight) \
        .options(contains_eager(Event.flight)) \
        .filter(or_(Event.flight == None, Flight.is_rankable())) \
        .order_by(Event.time.desc())

    query = _filter_query(query, request.args)

    page = request.args.get('page', type=int, default=1)
    per_page = request.args.get('per_page', type=int, default=50)

    events = query.limit(per_page).offset((page - 1) * per_page).all()

    return jsonify(events=(map(convert_event, events)))
Example #4
0
def _list():
    query = (
        Event.query()
        .options(subqueryload("user"))
        .options(subqueryload("club"))
        .outerjoin(Event.flight)
        .options(contains_eager(Event.flight))
        .filter(or_(Event.flight == None, Flight.is_rankable()))
        .order_by(Event.time.desc())
    )

    query = _filter_query(query, request.args)

    page = request.args.get("page", type=int, default=1)
    per_page = request.args.get("per_page", type=int, default=50)

    events = query.limit(per_page).offset((page - 1) * per_page).all()

    return jsonify(events=([convert_event(event) for event in events]))
Example #5
0
def index():
    if 'application/json' not in request.headers.get('Accept', ''):
        return render_template('ember-page.jinja')

    query = Event.query() \
        .options(subqueryload('actor')) \
        .options(subqueryload('user')) \
        .options(subqueryload('club')) \
        .outerjoin(Event.flight) \
        .options(contains_eager(Event.flight)) \
        .filter(or_(Event.flight == None, Flight.is_rankable())) \
        .order_by(Event.time.desc())

    query = _filter_query(query, request.args)

    page = request.args.get('page', type=int, default=1)
    per_page = request.args.get('per_page', type=int, default=50)

    events = query.limit(per_page).offset((page - 1) * per_page).all()

    return jsonify(events=(map(convert_event, events)))
def unlock_flight_achievements(flight):
    """Calculate new flight achievements for the pilot and store them in
    database.
    """
    pilot = flight.pilot
    assert pilot is not None

    unlocked_achievements = {a.name: a for a in pilot.achievements}
    achievements = get_flight_achievements(flight)

    newunlocked = []
    for a in achievements:
        time_achieved = flight.landing_time

        if a.name in unlocked_achievements:
            # check if flight was started prior the flight in existing
            # achievement and update both acievement and notification event in
            # this case.
            oldach = unlocked_achievements[a.name]
            if oldach.time_achieved > time_achieved:
                # reassign the flight
                oldach.flight = flight
                oldach.time_achieved = time_achieved
                # Update achievement event too
                event = Event.query(achievement_id=oldach.id).one()
                event.flight = flight

        else:
            newach = UnlockedAchievement(name=a.name,
                                         pilot=pilot,
                                         flight=flight,
                                         time_achieved=flight.landing_time)
            newunlocked.append(newach)
            db.session.add(newach)
            create_achievement_notification(newach)

    return newunlocked
Example #7
0
def unlock_flight_achievements(flight):
    """Calculate new flight achievements for the pilot and store them in
    database.
    """
    pilot = flight.pilot
    assert pilot is not None

    unlocked_achievements = {a.name: a for a in pilot.achievements}
    achievements = get_flight_achievements(flight)

    newunlocked = []
    for a in achievements:
        time_achieved = flight.landing_time

        if a.name in unlocked_achievements:
            # check if flight was started prior the flight in existing
            # achievement and update both acievement and notification event in
            # this case.
            oldach = unlocked_achievements[a.name]
            if oldach.time_achieved > time_achieved:
                # reassign the flight
                oldach.flight = flight
                oldach.time_achieved = time_achieved
                # Update achievement event too
                event = Event.query(achievement_id=oldach.id).one()
                event.flight = flight

        else:
            newach = UnlockedAchievement(name=a.name,
                                         pilot=pilot, flight=flight,
                                         time_achieved=flight.landing_time)
            newunlocked.append(newach)
            db.session.add(newach)
            create_achievement_notification(newach)

    return newunlocked