本文整理汇总了Python中skylines.api.json.jsonify函数的典型用法代码示例。如果您正苦于以下问题:Python jsonify函数的具体用法?Python jsonify怎么用?Python jsonify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了jsonify函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: create_club
def create_club():
current_user = User.get(request.user_id)
if not current_user:
return jsonify(error="invalid-token"), 401
json = request.get_json()
if json is None:
return jsonify(error="invalid-request"), 400
try:
data = ClubSchema(only=("name",)).load(json).data
except ValidationError as e:
return jsonify(error="validation-failed", fields=e.messages), 422
if Club.exists(name=data.get("name")):
return jsonify(error="duplicate-club-name"), 422
# create the new club
club = Club(**data)
club.owner_id = current_user.id
db.session.add(club)
db.session.flush()
# assign the user to the new club
current_user.club = club
# create the "user joined club" event
create_club_join_event(club.id, current_user)
db.session.commit()
return jsonify(id=club.id)
开发者ID:skylines-project,项目名称:skylines,代码行数:32,代码来源:clubs.py
示例2: 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
示例3: 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
示例4: new_post
def new_post():
json = request.get_json()
if json is None:
return jsonify(error='invalid-request'), 400
try:
data = CurrentUserSchema(only=('email', 'firstName', 'lastName', 'password')).load(json).data
except ValidationError, e:
return jsonify(error='validation-failed', fields=e.messages), 422
开发者ID:GliderGeek,项目名称:skylines,代码行数:9,代码来源:users.py
示例5: verify
def verify():
current_user = User.get(request.user_id)
json = request.get_json()
if json is None:
return jsonify(error='invalid-request'), 400
try:
data = FlightSchema(partial=True).load(json, many=True).data
except ValidationError, e:
return jsonify(error='validation-failed', fields=e.messages), 422
开发者ID:GliderGeek,项目名称:skylines,代码行数:11,代码来源:upload.py
示例6: 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
示例7: list
def list(ids):
if not ids:
return jsonify(), 400
try:
# Split the string into integer IDs
ids = [int(id) for id in ids.split(",")]
except ValueError:
return jsonify(), 404
return _create_list(pinned=ids, default_sorting_column="date", default_sorting_order="desc")
开发者ID:skylines-project,项目名称:skylines,代码行数:11,代码来源:flights.py
示例8: negotiate_locale
def negotiate_locale():
available = request.args.get("available", "").split(",")
available = [locale for locale in available if locale != ""]
if len(available) == 0:
return jsonify(error="invalid-request"), 400
preferred = [headers[0] for headers in request.accept_languages]
locale = _negotiate_locale(preferred, available, sep="-")
return jsonify(locale=locale)
开发者ID:skylines-project,项目名称:skylines,代码行数:12,代码来源:i18n.py
示例9: 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
示例10: 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
示例11: license
def license():
path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
'..', '..', '..', 'LICENSE')
with open(path) as f:
content = f.read().decode('utf-8')
return jsonify(content=content)
开发者ID:GliderGeek,项目名称:skylines,代码行数:7,代码来源:about.py
示例12: _list
def _list():
location = parse_location(request.args)
airspaces = airspace_list_schema.dump(Airspace.by_location(location).all(), many=True).data
waves = wave_list_schema.dump(MountainWaveProject.by_location(location), many=True).data
return jsonify(airspaces=airspaces, waves=waves)
开发者ID:RBE-Avionik,项目名称:skylines,代码行数:7,代码来源:mapitems.py
示例13: index
def index():
models = AircraftModel.query() \
.order_by(AircraftModel.kind) \
.order_by(AircraftModel.name) \
.all()
return jsonify(models=AircraftModelSchema().dump(models, many=True).data)
开发者ID:GliderGeek,项目名称:skylines,代码行数:7,代码来源:aircraft_models.py
示例14: latest
def latest():
fixes = []
for fix in TrackingFix.get_latest():
json = dict(
time=fix.time.isoformat() + "Z",
location=fix.location.to_wkt(),
pilot=dict(id=fix.pilot_id, name=fix.pilot.name),
)
optional_attributes = [
"track",
"ground_speed",
"airspeed",
"altitude",
"vario",
"engine_noise_level",
]
for attr in optional_attributes:
value = getattr(fix, attr)
if value is not None:
json[attr] = value
fixes.append(json)
return jsonify(fixes=fixes)
开发者ID:skylines-project,项目名称:skylines,代码行数:25,代码来源:tracking.py
示例15: _list
def _list():
query = (
Notification.query(recipient_id=request.user_id)
.join("event")
.options(contains_eager("event"))
.options(subqueryload("event.actor"))
.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)
query = query.limit(per_page)
query = query.offset((page - 1) * per_page)
def get_event(notification):
event = notification.event
event.unread = notification.time_read is None
return event
events = list(convert_event(get_event(notification)) for notification in query)
return jsonify(events=events)
开发者ID:skylines-project,项目名称:skylines,代码行数:28,代码来源:notifications.py
示例16: 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
示例17: index
def index():
fix_schema = TrackingFixSchema(only=('time', 'location', 'altitude', 'elevation', 'pilot'))
airport_schema = AirportSchema(only=('id', 'name', 'countryCode'))
@cache.memoize(timeout=(60 * 60))
def get_nearest_airport(track):
airport = Airport.by_location(track.location, None)
if not airport:
return None
return dict(airport=airport_schema.dump(airport).data,
distance=airport.distance(track.location))
tracks = []
for t in TrackingFix.get_latest():
nearest_airport = get_nearest_airport(t)
track = fix_schema.dump(t).data
if nearest_airport:
track['nearestAirport'] = nearest_airport['airport']
track['nearestAirportDistance'] = nearest_airport['distance']
tracks.append(track)
if request.user_id:
followers = [f.destination_id for f in Follower.query(source_id=request.user_id)]
else:
followers = []
return jsonify(friends=followers, tracks=tracks)
开发者ID:GliderGeek,项目名称:skylines,代码行数:30,代码来源:tracking.py
示例18: check_email
def check_email():
current_user = User.get(request.user_id) if request.user_id else None
json = request.get_json()
if not json:
return jsonify(error='invalid-request'), 400
email = json.get('email', '')
result = 'available'
if current_user and email == current_user.email_address:
result = 'self'
elif User.exists(email_address=email):
result = 'unavailable'
return jsonify(result=result)
开发者ID:RBE-Avionik,项目名称:skylines,代码行数:16,代码来源:users.py
示例19: skylines_team
def skylines_team():
path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
'..', '..', '..', 'AUTHORS.md')
with open(path) as f:
content = f.read().decode('utf-8')
return jsonify(content=content)
开发者ID:GliderGeek,项目名称:skylines,代码行数:7,代码来源:about.py
示例20: list
def list():
query = Notification.query(recipient_id=request.user_id) \
.join('event') \
.options(contains_eager('event')) \
.options(subqueryload('event.actor')) \
.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)
query = query.limit(per_page)
query = query.offset((page - 1) * per_page)
def get_event(notification):
event = notification.event
event.unread = (notification.time_read is None)
return event
events = map(get_event, query)
return jsonify(events=(map(convert_event, events)))
开发者ID:GliderGeek,项目名称:skylines,代码行数:26,代码来源:notifications.py
注:本文中的skylines.api.json.jsonify函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论