def _get_devices():
db = aeon_ztp.db.session
to_json = device_schema
# ---------------------------------------------------------------
# if the request has arguments, use these to form an "and" filter
# and return only the subset of items matching
# ---------------------------------------------------------------
if request.args:
try:
recs = find_devices(db, request.args.to_dict())
if len(recs) == 0:
return jsonify(ok=False,
message='Not Found: %s' % request.query_string), 404
items = [to_json.dump(rec).data for rec in recs]
return jsonify(count=len(items), items=items)
except AttributeError:
return jsonify(ok=False, message='invalid arguments'), 500
# -------------------------------------------
# otherwise, return all items in the database
# -------------------------------------------
items = [to_json.dump(rec).data for rec in db.query(Device).all()]
return jsonify(count=len(items), items=items)
# -----------------------------------------------------------------------------
# POST /api/devices
# -----------------------------------------------------------------------------
评论列表
文章目录