def api_monitor_index(): session = db_session() if request.method == "GET": monitors = [{"id":m.id, "name":m.name, "url": m.url, "interval": m.interval} for m in session.query(Monitor)] return jsonify(monitors=monitors) else: data = request.json monitor = Monitor(name=data["name"], url=data["url"], interval=data["interval"]) session.add(monitor) session.commit() return redirect(url_for("api_monitor", id=monitor.id))
def shutdown_session(exception=None): db_session().remove()