• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python dbutil.get_requested_record函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中skylines.lib.dbutil.get_requested_record函数的典型用法代码示例。如果您正苦于以下问题:Python get_requested_record函数的具体用法?Python get_requested_record怎么用?Python get_requested_record使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_requested_record函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: index

def index(page=None, id=None):
    if 'application/json' not in request.headers.get('Accept', ''):
        return render_template('ember-page.jinja', active_page='statistics')

    name = None

    query = db.session.query(Flight.year.label('year'),
                             func.count('*').label('flights'),
                             func.count(distinct(Flight.pilot_id)).label('pilots'),
                             func.sum(Flight.olc_classic_distance).label('distance'),
                             func.sum(Flight.duration).label('duration'))

    pilots_query = db.session.query(func.count(distinct(Flight.pilot_id)))

    if page == 'pilot':
        pilot = get_requested_record(User, id)
        name = unicode(pilot)
        query = query.filter(Flight.pilot_id == pilot.id)

    elif page == 'club':
        club = get_requested_record(Club, id)
        name = unicode(club)
        query = query.filter(Flight.club_id == club.id)
        pilots_query = pilots_query.filter(Flight.club_id == club.id)

    elif page == 'airport':
        airport = get_requested_record(Airport, id)
        name = unicode(airport)
        query = query.filter(Flight.takeoff_airport_id == airport.id)
        pilots_query = pilots_query.filter(Flight.takeoff_airport_id == airport.id)

    elif page is not None:
        abort(404)

    query = query.filter(Flight.is_rankable())

    query = query.group_by(Flight.year).order_by(Flight.year.desc())

    if page == 'pilot':
        sum_pilots = 0
    else:
        sum_pilots = pilots_query.scalar()

    list = []
    for row in query:
        row.average_distance = row.distance / row.flights
        row.average_duration = row.duration / row.flights

        list.append({
            'year': row.year,
            'flights': row.flights,
            'distance': row.distance,
            'duration': row.duration.total_seconds(),
            'pilots': row.pilots,
            'average_distance': row.distance / row.flights,
            'average_duration': row.duration.total_seconds() / row.flights,
        })

    return jsonify(name=name, years=list, sumPilots=sum_pilots)
开发者ID:kerel-fs,项目名称:skylines,代码行数:59,代码来源:statistics.py


示例2: index

def index(page=None, id=None):
    name = None

    query = db.session.query(
        Flight.year.label("year"),
        func.count("*").label("flights"),
        func.count(distinct(Flight.pilot_id)).label("pilots"),
        func.sum(Flight.olc_classic_distance).label("distance"),
        func.sum(Flight.duration).label("duration"),
    )

    pilots_query = db.session.query(func.count(distinct(Flight.pilot_id)))

    if page == "pilot":
        pilot = get_requested_record(User, id)
        name = pilot.name
        query = query.filter(Flight.pilot_id == pilot.id)

    elif page == "club":
        club = get_requested_record(Club, id)
        name = club.name
        query = query.filter(Flight.club_id == club.id)
        pilots_query = pilots_query.filter(Flight.club_id == club.id)

    elif page == "airport":
        airport = get_requested_record(Airport, id)
        name = airport.name
        query = query.filter(Flight.takeoff_airport_id == airport.id)
        pilots_query = pilots_query.filter(Flight.takeoff_airport_id == airport.id)

    elif page is not None:
        abort(404)

    query = query.filter(Flight.is_rankable())

    query = query.group_by(Flight.year).order_by(Flight.year.desc())

    if page == "pilot":
        sum_pilots = 0
    else:
        sum_pilots = pilots_query.scalar()

    list = []
    for row in query:
        list.append(
            {
                "year": row.year,
                "flights": row.flights,
                "distance": row.distance,
                "duration": row.duration.total_seconds(),
                "pilots": row.pilots,
                "average_distance": row.distance / row.flights,
                "average_duration": row.duration.total_seconds() / row.flights,
            }
        )

    return jsonify(name=name, years=list, sumPilots=sum_pilots)
开发者ID:skylines-project,项目名称:skylines,代码行数:57,代码来源:statistics.py


示例3: near

def near(flight_id):
    flight = get_requested_record(Flight, flight_id, joinedload=[Flight.igc_file])

    current_user = User.get(request.user_id) if request.user_id else None
    if not flight.is_viewable(current_user):
        return jsonify(), 404

    try:
        latitude = float(request.args["lat"])
        longitude = float(request.args["lon"])
        time = float(request.args["time"])

    except (KeyError, ValueError):
        abort(400)

    location = Location(latitude=latitude, longitude=longitude)
    time = from_seconds_of_day(flight.takeoff_time, time)

    flights = _get_near_flights(flight, location, time, 1000)

    def add_flight_path(flight):
        trace = _get_flight_path(flight, threshold=0.0001, max_points=10000)
        trace["additional"] = dict(registration=flight.registration, competition_id=flight.competition_id)

        return trace

    return jsonify(flights=map(add_flight_path, flights))
开发者ID:skylines-project,项目名称:skylines,代码行数:27,代码来源:flights.py


示例4: add_comment

def add_comment(flight_id):
    flight = get_requested_record(Flight, flight_id)

    current_user = User.get(request.user_id)
    if not current_user:
        return jsonify(), 403

    json = request.get_json()
    if json is None:
        return jsonify(error="invalid-request"), 400

    try:
        data = FlightCommentSchema().load(json).data
    except ValidationError as e:
        return jsonify(error="validation-failed", fields=e.messages), 422

    comment = FlightComment()
    comment.user = current_user
    comment.flight = flight
    comment.text = data["text"]

    create_flight_comment_notifications(comment)

    db.session.commit()

    return jsonify()
开发者ID:skylines-project,项目名称:skylines,代码行数:26,代码来源:flights.py


示例5: update

def update(club_id):
    current_user = User.get(request.user_id)
    if not current_user:
        return jsonify(error="invalid-token"), 401

    club = get_requested_record(Club, club_id)
    if not club.is_writable(current_user):
        return jsonify(error="forbidden"), 403

    json = request.get_json()
    if json is None:
        return jsonify(error="invalid-request"), 400

    try:
        data = ClubSchema(partial=True).load(json).data
    except ValidationError as e:
        return jsonify(error="validation-failed", fields=e.messages), 422

    if "name" in data:
        name = data.get("name")

        if name != club.name and Club.exists(name=name):
            return jsonify(error="duplicate-club-name"), 422

        club.name = name

    if "website" in data:
        club.website = data.get("website")

    db.session.commit()

    return jsonify()
开发者ID:skylines-project,项目名称:skylines,代码行数:32,代码来源:clubs.py


示例6: follow

def follow(user_id):
    user = get_requested_record(User, user_id)
    current_user = User.get(request.user_id)
    Follower.follow(current_user, user)
    create_follower_notification(user, current_user)
    db.session.commit()
    return jsonify()
开发者ID:skylines-project,项目名称:skylines,代码行数:7,代码来源:users.py


示例7: pilot

def pilot(id):
    pilot = get_requested_record(User, id)

    mark_flight_notifications_read(pilot)

    return _create_list('pilot', request.args, pilot=pilot,
                        default_sorting_column='date', default_sorting_order='desc')
开发者ID:Adrien81,项目名称:skylines,代码行数:7,代码来源:flights.py


示例8: pilot

def pilot(id):
    pilot = get_requested_record(User, id)

    mark_user_notifications_read(pilot)

    return _create_list(
        pilot=pilot, default_sorting_column="date", default_sorting_order="desc"
    )
开发者ID:skylines-project,项目名称:skylines,代码行数:8,代码来源:flights.py


示例9: _lookup

    def _lookup(self, id, *remainder):
        # Fallback for old URLs
        if id == 'id' and len(remainder) > 0:
            id = remainder[0]
            remainder = remainder[1:]

        controller = UserController(get_requested_record(User, id))
        return controller, remainder
开发者ID:gabor-konrad,项目名称:Skylines,代码行数:8,代码来源:users.py


示例10: read

def read(club_id):
    current_user = User.get(request.user_id) if request.user_id else None

    club = get_requested_record(Club, club_id)

    json = ClubSchema().dump(club).data
    json["isWritable"] = club.is_writable(current_user) or False

    return jsonify(json)
开发者ID:skylines-project,项目名称:skylines,代码行数:9,代码来源:clubs.py


示例11: _lookup

    def _lookup(self, id, *remainder):
        if not request.identity:
            raise HTTPForbidden

        notification = get_requested_record(Notification, id)
        if request.identity['user'] != notification.recipient:
            raise HTTPForbidden

        controller = NotificationController(notification)
        return controller, remainder
开发者ID:citterio,项目名称:Skylines,代码行数:10,代码来源:notifications.py


示例12: index

def index(airport_id):
    airport = get_requested_record(Airport, airport_id)

    json = {
        'id': airport.id,
        'name': unicode(airport),
        'countryCode': airport.country_code,
    }

    return jsonify(**json)
开发者ID:kerel-fs,项目名称:skylines,代码行数:10,代码来源:airport.py


示例13: delete_user

def delete_user(user_id):
    current_user = User.get(request.user_id)
    if not current_user.is_manager():
        return jsonify(), 403

    user = get_requested_record(User, user_id)

    user.delete()
    db.session.commit()

    return jsonify()
开发者ID:skylines-project,项目名称:skylines,代码行数:11,代码来源:users.py


示例14: delete

def delete(flight_id):
    flight = get_requested_record(Flight, flight_id, joinedload=[Flight.igc_file])

    current_user = User.get(request.user_id)
    if not flight.is_writable(current_user):
        abort(403)

    files.delete_file(flight.igc_file.filename)
    db.session.delete(flight)
    db.session.delete(flight.igc_file)
    db.session.commit()

    return jsonify()
开发者ID:skylines-project,项目名称:skylines,代码行数:13,代码来源:flights.py


示例15: json

def json(flight_id):
    flight = get_requested_record(
        Flight, flight_id, joinedload=(Flight.igc_file, Flight.model)
    )

    current_user = User.get(request.user_id) if request.user_id else None
    if not flight.is_viewable(current_user):
        return jsonify(), 404

    # Return HTTP Status code 304 if an upstream or browser cache already
    # contains the response and if the igc file did not change to reduce
    # latency and server load
    # This implementation is very basic. Sadly Flask (0.10.1) does not have
    # this feature
    last_modified = flight.time_modified.strftime("%a, %d %b %Y %H:%M:%S GMT")
    modified_since = request.headers.get("If-Modified-Since")
    etag = request.headers.get("If-None-Match")
    if (modified_since and modified_since == last_modified) or (
        etag and etag == flight.igc_file.md5
    ):
        return ("", 304)

    trace = _get_flight_path(flight, threshold=0.0001, max_points=10000)
    if not trace:
        abort(404)

    model = AircraftModelSchema().dump(flight.model).data or None

    resp = make_response(
        jsonify(
            points=trace["points"],
            barogram_t=trace["barogram_t"],
            barogram_h=trace["barogram_h"],
            enl=trace["enl"],
            contests=trace["contests"],
            elevations_t=trace["elevations_t"],
            elevations_h=trace["elevations_h"],
            sfid=flight.id,
            geoid=trace["geoid"],
            additional=dict(
                registration=flight.registration,
                competition_id=flight.competition_id,
                model=model,
            ),
        )
    )

    resp.headers["Last-Modified"] = last_modified
    resp.headers["Etag"] = flight.igc_file.md5
    return resp
开发者ID:skylines-project,项目名称:skylines,代码行数:50,代码来源:flights.py


示例16: update

def update(flight_id):
    flight = get_requested_record(Flight, flight_id)

    current_user = User.get(request.user_id)
    if not flight.is_writable(current_user):
        return jsonify(), 403

    json = request.get_json()
    if json is None:
        return jsonify(error="invalid-request"), 400

    try:
        data = FlightSchema(partial=True).load(json).data
    except ValidationError, e:
        return jsonify(error="validation-failed", fields=e.messages), 422
开发者ID:skylines-project,项目名称:skylines,代码行数:15,代码来源:flights.py


示例17: airport

    def airport(self, id, **kw):
        airport = get_requested_record(Airport, id)

        columns = {
            0: 'takeoff_time',
            1: 'olc_plus_score',
            2: 'display_name',
            3: 'olc_classic_distance',
            4: 'flights.club_id',
            5: 'models.name',
            6: 'takeoff_time',
            7: 'id',
            8: 'num_comments',
        }

        return self.__do_list('airport', kw, airport=airport, columns=columns)
开发者ID:Plantain,项目名称:Skylines,代码行数:16,代码来源:flights.py


示例18: json

def json(user_id):
    pilot = get_requested_record(User, user_id, joinedload=[User.club])
    last_update = request.values.get('last_update', 0, type=int)

    trace = _get_flight_path(pilot, threshold=0.001, last_update=last_update)
    if not trace:
        abort(404)

    return jsonify(
        points=trace['points'],
        barogram_t=trace['barogram_t'],
        barogram_h=trace['barogram_h'],
        elevations=trace['elevations'],
        enl=trace['enl'],
        geoid=trace['geoid'],
        sfid=pilot.id)
开发者ID:GliderGeek,项目名称:skylines,代码行数:16,代码来源:tracking.py


示例19: club

    def club(self, id, **kw):
        club = get_requested_record(Club, id)

        columns = {
            0: 'takeoff_time',
            1: 'olc_plus_score',
            2: 'display_name',
            3: 'olc_classic_distance',
            4: 'airports.name',
            5: 'models.name',
            6: 'takeoff_time',
            7: 'id',
            8: 'num_comments',
        }

        return self.__do_list('club', kw, club=club, columns=columns)
开发者ID:Plantain,项目名称:Skylines,代码行数:16,代码来源:flights.py


示例20: followers

def followers(user_id):
    user = get_requested_record(User, user_id)

    # Query list of pilots that are following the selected user
    query = Follower.query(destination=user) \
        .join('source') \
        .options(contains_eager('source')) \
        .options(subqueryload('source.club')) \
        .order_by(User.name)

    user_schema = UserSchema(only=('id', 'name', 'club'))
    followers = user_schema.dump([follower.source for follower in query], many=True).data

    add_current_user_follows(followers)

    return jsonify(followers=followers)
开发者ID:RBE-Avionik,项目名称:skylines,代码行数:16,代码来源:users.py



注:本文中的skylines.lib.dbutil.get_requested_record函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python model.DBSession类代码示例发布时间:2022-05-27
下一篇:
Python json.jsonify函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap