@app.route('/notes/<hostname>', methods=['GET', 'POST'])
@login_required
def list_notes(hostname):
    """Retrieve a list of notes associated with a host. Or given
      {'user': 'username', 'note': 'some message'} post a note."""
    if request.method == 'GET':
        try:
            #someday i should probably add offset support here and in the statelog
            limit = request.args.get('limit', 50, type=int)
        except __HOLE__:
            abort(400)
        notes = list(r.table("notes").filter({"hostname": hostname}).order_by(r.desc("ts")).limit(limit).run(rdb.conn))
        if notes:
            return jsonify({'notes': sorted(notes, key=lambda k: k['ts'])})
        else:
            abort(404)
    elif request.method == 'POST':
        if not request.json:
            abort(400)
        if not request.json.get("user") or not request.json.get("note"):
            abort(400)
        if not r.table("hosts").get_all(hostname, index="hostname").run(rdb.conn):
            abort(404)
        alerting = [x["check"] for x in r.table("checks").filter({"h stname": hostname, "status": False}).run(rdb.conn)]
        q = r.table("notes").insert({'hostname': hostname, 'user': request.json.get("user"),
                                     'note': request.json.get("note"), 'ts': time(), 'alerting': alerting}).run(rdb.conn)
        if q["inserted"] == 1:
            return jsonify({'success': True})
        else:
            logger.error(q)
            abort(500)
    else:
        abort(400)
dataset/ETHPy150Open pandemicsyn/stalker/stalkerweb/stalkerweb/views.py/list_notes