Exemple #1
0
def _handle_request(model, flight_field):
    current_year = date.today().year
    year = _parse_year()
    result = _get_result(model, flight_field, year=year)

    result = Sorter.sort(result, 'sorter', 'rank',
                         valid_columns={'rank': 'rank',
                                        'count': 'count',
                                        'total': 'total'},
                         default_order='asc')
    result = Pager.paginate(result, 'result')
    return dict(year=year, current_year=current_year, result=result)
Exemple #2
0
def _handle_request(model, flight_field):
    current_year = date.today().year
    year = _parse_year()
    result = _get_result(model, flight_field, year=year)

    result = Sorter.sort(result, 'sorter', 'rank',
                         valid_columns={'rank': 'rank',
                                        'count': 'count',
                                        'total': 'total'},
                         default_order='asc')
    result = Pager.paginate(result, 'result')
    return dict(year=year, current_year=current_year, result=result)
Exemple #3
0
def _handle_request(model, flight_field):
    current_year = date.today().year
    year = _parse_year()
    result = _get_result(model, flight_field, year=year)

    result = Sorter.sort(
        result,
        "sorter",
        "rank",
        valid_columns={"rank": "rank", "count": "count", "total": "total"},
        default_order="asc",
    )
    result = Pager.paginate(result, "result")
    return dict(year=year, current_year=current_year, result=result)
Exemple #4
0
def _handle_request_flight_user_byClub():
    current_year = date.today().year
    year = _parse_year()
    result = _get_result_Flight_User_byClub(year=year)

    result = Sorter.sort(
        result,
        "sorter",
        "flights",
        valid_columns={
            "flights": "flights_count",
            "users": "users_count",
            "rank": "rank"
        },
        default_order="desc",
    )

    result = Pager.paginate(result, "result")
    return dict(year=year, current_year=current_year, result=result)
Exemple #5
0
def _create_list(date=None,
                 pilot=None,
                 club=None,
                 airport=None,
                 pinned=None,
                 filter=None,
                 default_sorting_column='score',
                 default_sorting_order='desc'):

    pilot_alias = aliased(User, name='pilot')
    owner_alias = aliased(User, name='owner')

    subq = db.session \
        .query(FlightComment.flight_id, func.count('*').label('count')) \
        .group_by(FlightComment.flight_id).subquery()

    current_user = User.get(request.user_id) if request.user_id else None

    flights = db.session.query(Flight, subq.c.count) \
        .filter(Flight.is_listable(current_user)) \
        .join(Flight.igc_file) \
        .options(contains_eager(Flight.igc_file)) \
        .join(owner_alias, IGCFile.owner) \
        .options(contains_eager(Flight.igc_file, IGCFile.owner, alias=owner_alias)) \
        .outerjoin(pilot_alias, Flight.pilot) \
        .options(contains_eager(Flight.pilot, alias=pilot_alias)) \
        .options(joinedload(Flight.co_pilot)) \
        .outerjoin(Flight.club) \
        .options(contains_eager(Flight.club)) \
        .outerjoin(Flight.takeoff_airport) \
        .options(contains_eager(Flight.takeoff_airport)) \
        .outerjoin(Flight.model) \
        .options(contains_eager(Flight.model)) \
        .outerjoin((subq, Flight.comments))

    if date:
        flights = flights.filter(Flight.date_local == date)

    if pilot:
        flights = flights.filter(
            or_(Flight.pilot == pilot, Flight.co_pilot == pilot))
    if club:
        flights = flights.filter(Flight.club == club)

    if airport:
        flights = flights.filter(Flight.takeoff_airport == airport)

    if pinned:
        flights = flights.filter(Flight.id.in_(pinned))

    if filter is not None:
        flights = flights.filter(filter)

    valid_columns = {
        'date': getattr(Flight, 'date_local'),
        'score': getattr(Flight, 'index_score'),
        'pilot': getattr(pilot_alias, 'name'),
        'distance': getattr(Flight, 'olc_classic_distance'),
        'airport': getattr(Airport, 'name'),
        'club': getattr(Club, 'name'),
        'aircraft': getattr(AircraftModel, 'name'),
        'time': getattr(Flight, 'takeoff_time'),
    }

    flights_count = flights.count()

    flights = Sorter.sort(flights,
                          'flights',
                          default_sorting_column,
                          valid_columns=valid_columns,
                          default_order=default_sorting_order)

    flights = flights.order_by(Flight.index_score.desc())

    flights = Pager.paginate(flights,
                             'flights',
                             items_per_page=int(
                                 current_app.config.get(
                                     'SKYLINES_LISTS_DISPLAY_LENGTH', 50)))

    flight_schema = FlightSchema()
    flights_json = []
    for f, num_comments in flights:
        flight = flight_schema.dump(f).data
        flight['private'] = not f.is_rankable()
        flight['numComments'] = num_comments
        flights_json.append(flight)

    json = dict(flights=flights_json, count=flights_count)

    if date:
        json['date'] = date.isoformat()

    if pilot:
        user_schema = UserSchema(only=('id', 'name'))
        json['pilot'] = user_schema.dump(pilot).data

    if club:
        club_schema = ClubSchema(only=('id', 'name'))
        json['club'] = club_schema.dump(club).data

    if airport:
        airport_schema = AirportSchema(only=('id', 'name', 'countryCode'))
        json['airport'] = airport_schema.dump(airport).data

    return jsonify(json)
Exemple #6
0
def _create_list(tab, kw, date=None, pilot=None, club=None, airport=None,
                 pinned=None, filter=None,
                 default_sorting_column='score', default_sorting_order='desc'):
    pilot_alias = aliased(User, name='pilot')
    owner_alias = aliased(User, name='owner')

    subq = db.session \
        .query(FlightComment.flight_id, func.count('*').label('count')) \
        .group_by(FlightComment.flight_id).subquery()

    flights = db.session.query(Flight, subq.c.count) \
        .filter(Flight.is_listable(g.current_user)) \
        .join(Flight.igc_file) \
        .options(contains_eager(Flight.igc_file)) \
        .join(owner_alias, IGCFile.owner) \
        .options(contains_eager(Flight.igc_file, IGCFile.owner, alias=owner_alias)) \
        .outerjoin(pilot_alias, Flight.pilot) \
        .options(contains_eager(Flight.pilot, alias=pilot_alias)) \
        .options(joinedload(Flight.co_pilot)) \
        .outerjoin(Flight.club) \
        .options(contains_eager(Flight.club)) \
        .outerjoin(Flight.takeoff_airport) \
        .options(contains_eager(Flight.takeoff_airport)) \
        .outerjoin(Flight.model) \
        .options(contains_eager(Flight.model)) \
        .outerjoin((subq, Flight.comments))

    if date:
        flights = flights.filter(Flight.date_local == date)

    if pilot:
        flights = flights.filter(or_(Flight.pilot == pilot,
                                     Flight.co_pilot == pilot))
    if club:
        flights = flights.filter(Flight.club == club)

    if airport:
        flights = flights.filter(Flight.takeoff_airport == airport)

    if pinned:
        flights = flights.filter(Flight.id.in_(pinned))

    if filter is not None:
        flights = flights.filter(filter)

    valid_columns = {
        'date': getattr(Flight, 'date_local'),
        'score': getattr(Flight, 'index_score'),
        'pilot': getattr(pilot_alias, 'name'),
        'distance': getattr(Flight, 'olc_classic_distance'),
        'airport': getattr(Airport, 'name'),
        'club': getattr(Club, 'name'),
        'aircraft': getattr(AircraftModel, 'name'),
        'time': getattr(Flight, 'takeoff_time'),
    }

    flights_count = flights.count()

    flights = Sorter.sort(flights, 'flights', default_sorting_column,
                          valid_columns=valid_columns,
                          default_order=default_sorting_order)

    flights = flights.order_by(Flight.index_score.desc())

    flights = Pager.paginate(flights, 'flights',
                             items_per_page=int(current_app.config.get('SKYLINES_LISTS_DISPLAY_LENGTH', 50)))

    return render_template('flights/list.jinja',
                           tab=tab, date=date, pilot=pilot, club=club,
                           airport=airport, flights=flights,
                           flights_count=flights_count)
Exemple #7
0
def _create_list(
    date=None,
    pilot=None,
    club=None,
    airport=None,
    pinned=None,
    filter=None,
    default_sorting_column="score",
    default_sorting_order="desc",
):

    pilot_alias = aliased(User, name="pilot")
    owner_alias = aliased(User, name="owner")

    subq = (db.session.query(FlightComment.flight_id,
                             func.count("*").label("count")).group_by(
                                 FlightComment.flight_id).subquery())

    current_user = User.get(request.user_id) if request.user_id else None

    flights = (db.session.query(Flight, subq.c.count).filter(
        Flight.is_listable(current_user)).join(Flight.igc_file).options(
            contains_eager(Flight.igc_file)).join(
                owner_alias, IGCFile.owner).options(
                    contains_eager(Flight.igc_file,
                                   IGCFile.owner,
                                   alias=owner_alias)).outerjoin(
                                       pilot_alias, Flight.pilot).options(
                                           contains_eager(Flight.pilot,
                                                          alias=pilot_alias)).
               options(joinedload(Flight.co_pilot)).outerjoin(
                   Flight.club).options(contains_eager(Flight.club)).outerjoin(
                       Flight.takeoff_airport).options(
                           contains_eager(Flight.takeoff_airport)).outerjoin(
                               Flight.model).options(
                                   contains_eager(Flight.model)).outerjoin(
                                       (subq, Flight.comments)))

    if date:
        flights = flights.filter(Flight.date_local == date)

    if pilot:
        flights = flights.filter(
            or_(Flight.pilot == pilot, Flight.co_pilot == pilot))
    if club:
        flights = flights.filter(Flight.club == club)

    if airport:
        flights = flights.filter(Flight.takeoff_airport == airport)

    if pinned:
        flights = flights.filter(Flight.id.in_(pinned))

    if filter is not None:
        flights = flights.filter(filter)

    valid_columns = {
        "date": getattr(Flight, "date_local"),
        "score": getattr(Flight, "index_score"),
        "pilot": getattr(pilot_alias, "name"),
        "distance": getattr(Flight, "olc_classic_distance"),
        "airport": getattr(Airport, "name"),
        "club": getattr(Club, "name"),
        "aircraft": getattr(AircraftModel, "name"),
        "time": getattr(Flight, "takeoff_time"),
    }

    flights_count = flights.count()

    flights = Sorter.sort(
        flights,
        "flights",
        default_sorting_column,
        valid_columns=valid_columns,
        default_order=default_sorting_order,
    )

    flights = flights.order_by(Flight.index_score.desc())

    flights = Pager.paginate(
        flights,
        "flights",
        items_per_page=int(
            current_app.config.get("SKYLINES_LISTS_DISPLAY_LENGTH", 50)),
    )

    flight_schema = FlightSchema()
    flights_json = []
    for f, num_comments in flights:
        flight = flight_schema.dump(f).data
        flight["private"] = not f.is_rankable()
        flight["numComments"] = num_comments
        flights_json.append(flight)

    json = dict(flights=flights_json, count=flights_count)

    if date:
        json["date"] = date.isoformat()

    if pilot:
        user_schema = UserSchema(only=("id", "name"))
        json["pilot"] = user_schema.dump(pilot).data

    if club:
        club_schema = ClubSchema(only=("id", "name"))
        json["club"] = club_schema.dump(club).data

    if airport:
        airport_schema = AirportSchema(only=("id", "name", "countryCode"))
        json["airport"] = airport_schema.dump(airport).data

    return jsonify(json)
Exemple #8
0
def _create_list(tab,
                 kw,
                 date=None,
                 pilot=None,
                 club=None,
                 airport=None,
                 pinned=None,
                 filter=None,
                 default_sorting_column='score',
                 default_sorting_order='desc'):
    pilot_alias = aliased(User, name='pilot')
    owner_alias = aliased(User, name='owner')

    subq = db.session \
        .query(FlightComment.flight_id, func.count('*').label('count')) \
        .group_by(FlightComment.flight_id).subquery()

    flights = db.session.query(Flight, subq.c.count) \
        .filter(Flight.is_listable(g.current_user)) \
        .join(Flight.igc_file) \
        .options(contains_eager(Flight.igc_file)) \
        .join(owner_alias, IGCFile.owner) \
        .options(contains_eager(Flight.igc_file, IGCFile.owner, alias=owner_alias)) \
        .outerjoin(pilot_alias, Flight.pilot) \
        .options(contains_eager(Flight.pilot, alias=pilot_alias)) \
        .options(joinedload(Flight.co_pilot)) \
        .outerjoin(Flight.club) \
        .options(contains_eager(Flight.club)) \
        .outerjoin(Flight.takeoff_airport) \
        .options(contains_eager(Flight.takeoff_airport)) \
        .outerjoin(Flight.model) \
        .options(contains_eager(Flight.model)) \
        .outerjoin((subq, Flight.comments))

    if date:
        flights = flights.filter(Flight.date_local == date)

    if pilot:
        flights = flights.filter(
            or_(Flight.pilot == pilot, Flight.co_pilot == pilot))
    if club:
        flights = flights.filter(Flight.club == club)

    if airport:
        flights = flights.filter(Flight.takeoff_airport == airport)

    if pinned:
        flights = flights.filter(Flight.id.in_(pinned))

    if filter is not None:
        flights = flights.filter(filter)

    valid_columns = {
        'date': getattr(Flight, 'date_local'),
        'score': getattr(Flight, 'index_score'),
        'pilot': getattr(pilot_alias, 'name'),
        'distance': getattr(Flight, 'olc_classic_distance'),
        'airport': getattr(Airport, 'name'),
        'club': getattr(Club, 'name'),
        'aircraft': getattr(AircraftModel, 'name'),
        'time': getattr(Flight, 'takeoff_time'),
    }

    flights_count = flights.count()

    flights = Sorter.sort(flights,
                          'flights',
                          default_sorting_column,
                          valid_columns=valid_columns,
                          default_order=default_sorting_order)

    flights = flights.order_by(Flight.index_score.desc())

    flights = Pager.paginate(flights,
                             'flights',
                             items_per_page=int(
                                 current_app.config.get(
                                     'SKYLINES_LISTS_DISPLAY_LENGTH', 50)))

    return render_template('flights/list.jinja',
                           tab=tab,
                           date=date,
                           pilot=pilot,
                           club=club,
                           airport=airport,
                           flights=flights,
                           flights_count=flights_count)
Exemple #9
0
def _create_list(
    date=None,
    pilot=None,
    club=None,
    airport=None,
    pinned=None,
    filter=None,
    default_sorting_column="score",
    default_sorting_order="desc",
):

    pilot_alias = aliased(User, name="pilot")
    owner_alias = aliased(User, name="owner")

    subq = (
        db.session.query(FlightComment.flight_id, func.count("*").label("count"))
        .group_by(FlightComment.flight_id)
        .subquery()
    )

    current_user = User.get(request.user_id) if request.user_id else None

    flights = (
        db.session.query(Flight, subq.c.count)
        .filter(Flight.is_listable(current_user))
        .join(Flight.igc_file)
        .options(contains_eager(Flight.igc_file))
        .join(owner_alias, IGCFile.owner)
        .options(contains_eager(Flight.igc_file, IGCFile.owner, alias=owner_alias))
        .outerjoin(pilot_alias, Flight.pilot)
        .options(contains_eager(Flight.pilot, alias=pilot_alias))
        .options(joinedload(Flight.co_pilot))
        .outerjoin(Flight.club)
        .options(contains_eager(Flight.club))
        .outerjoin(Flight.takeoff_airport)
        .options(contains_eager(Flight.takeoff_airport))
        .outerjoin(Flight.model)
        .options(contains_eager(Flight.model))
        .outerjoin((subq, Flight.comments))
    )

    if date:
        flights = flights.filter(Flight.date_local == date)

    if pilot:
        flights = flights.filter(or_(Flight.pilot == pilot, Flight.co_pilot == pilot))
    if club:
        flights = flights.filter(Flight.club == club)

    if airport:
        flights = flights.filter(Flight.takeoff_airport == airport)

    if pinned:
        flights = flights.filter(Flight.id.in_(pinned))

    if filter is not None:
        flights = flights.filter(filter)

    valid_columns = {
        "date": getattr(Flight, "date_local"),
        "score": getattr(Flight, "index_score"),
        "pilot": getattr(pilot_alias, "name"),
        "distance": getattr(Flight, "olc_classic_distance"),
        "airport": getattr(Airport, "name"),
        "club": getattr(Club, "name"),
        "aircraft": getattr(AircraftModel, "name"),
        "time": getattr(Flight, "takeoff_time"),
    }

    flights_count = flights.count()

    flights = Sorter.sort(
        flights, "flights", default_sorting_column, valid_columns=valid_columns, default_order=default_sorting_order
    )

    flights = flights.order_by(Flight.index_score.desc())

    flights = Pager.paginate(
        flights, "flights", items_per_page=int(current_app.config.get("SKYLINES_LISTS_DISPLAY_LENGTH", 50))
    )

    flight_schema = FlightSchema()
    flights_json = []
    for f, num_comments in flights:
        flight = flight_schema.dump(f).data
        flight["private"] = not f.is_rankable()
        flight["numComments"] = num_comments
        flights_json.append(flight)

    json = dict(flights=flights_json, count=flights_count)

    if date:
        json["date"] = date.isoformat()

    if pilot:
        user_schema = UserSchema(only=("id", "name"))
        json["pilot"] = user_schema.dump(pilot).data

    if club:
        club_schema = ClubSchema(only=("id", "name"))
        json["club"] = club_schema.dump(club).data

    if airport:
        airport_schema = AirportSchema(only=("id", "name", "countryCode"))
        json["airport"] = airport_schema.dump(airport).data

    return jsonify(json)
Exemple #10
0
def _create_list(date=None, pilot=None, club=None, airport=None,
                 pinned=None, filter=None,
                 default_sorting_column='score', default_sorting_order='desc'):

    pilot_alias = aliased(User, name='pilot')
    owner_alias = aliased(User, name='owner')

    subq = db.session \
        .query(FlightComment.flight_id, func.count('*').label('count')) \
        .group_by(FlightComment.flight_id).subquery()

    current_user = User.get(request.user_id) if request.user_id else None

    flights = db.session.query(Flight, subq.c.count) \
        .filter(Flight.is_listable(current_user)) \
        .join(Flight.igc_file) \
        .options(contains_eager(Flight.igc_file)) \
        .join(owner_alias, IGCFile.owner) \
        .options(contains_eager(Flight.igc_file, IGCFile.owner, alias=owner_alias)) \
        .outerjoin(pilot_alias, Flight.pilot) \
        .options(contains_eager(Flight.pilot, alias=pilot_alias)) \
        .options(joinedload(Flight.co_pilot)) \
        .outerjoin(Flight.club) \
        .options(contains_eager(Flight.club)) \
        .outerjoin(Flight.takeoff_airport) \
        .options(contains_eager(Flight.takeoff_airport)) \
        .outerjoin(Flight.model) \
        .options(contains_eager(Flight.model)) \
        .outerjoin((subq, Flight.comments))

    if date:
        flights = flights.filter(Flight.date_local == date)

    if pilot:
        flights = flights.filter(or_(Flight.pilot == pilot,
                                     Flight.co_pilot == pilot))
    if club:
        flights = flights.filter(Flight.club == club)

    if airport:
        flights = flights.filter(Flight.takeoff_airport == airport)

    if pinned:
        flights = flights.filter(Flight.id.in_(pinned))

    if filter is not None:
        flights = flights.filter(filter)

    valid_columns = {
        'date': getattr(Flight, 'date_local'),
        'score': getattr(Flight, 'index_score'),
        'pilot': getattr(pilot_alias, 'name'),
        'distance': getattr(Flight, 'olc_classic_distance'),
        'airport': getattr(Airport, 'name'),
        'club': getattr(Club, 'name'),
        'aircraft': getattr(AircraftModel, 'name'),
        'time': getattr(Flight, 'takeoff_time'),
    }

    flights_count = flights.count()

    flights = Sorter.sort(flights, 'flights', default_sorting_column,
                          valid_columns=valid_columns,
                          default_order=default_sorting_order)

    flights = flights.order_by(Flight.index_score.desc())

    flights = Pager.paginate(flights, 'flights',
                             items_per_page=int(current_app.config.get('SKYLINES_LISTS_DISPLAY_LENGTH', 50)))

    flight_schema = FlightSchema()
    flights_json = []
    for f, num_comments in flights:
        flight = flight_schema.dump(f).data
        flight['private'] = not f.is_rankable()
        flight['numComments'] = num_comments
        flights_json.append(flight)

    json = dict(flights=flights_json, count=flights_count)

    if date:
        json['date'] = date.isoformat()

    if pilot:
        user_schema = UserSchema(only=('id', 'name'))
        json['pilot'] = user_schema.dump(pilot).data

    if club:
        club_schema = ClubSchema(only=('id', 'name'))
        json['club'] = club_schema.dump(club).data

    if airport:
        airport_schema = AirportSchema(only=('id', 'name', 'countryCode'))
        json['airport'] = airport_schema.dump(airport).data

    return jsonify(json)