Example #1
0
        latitude=latitude,
        longitude=longitude,
        id=location["id"],
        order=data["order"],
    )


@app.route("/locations/<location_id>", methods=["PUT"])
def update_location(location_id):
    data = request.json
    locations = get_collection()
    locations.update({"_id": ObjectId(location_id)}, {"$set": data})
    return jsonify(message="OK")


@app.route("/locations/<location_id>", methods=["DELETE"])
def delete_location(location_id):
    locations = get_collection()
    locations.remove(ObjectId(location_id))
    return jsonify(message="OK")


def get_collection():
    conn = pymongo.Connection("localhost:27017")
    return conn[app.db_name].locations


if __name__ == "__main__":

    app.db_name = "locations_prod"
    app.run(host="0.0.0.0")
Example #2
0
    todos.update({"_id": ObjectId(todo_id)}, {"$set": data})
    return make_json_response({"message": "OK"})


@app.route("/todos/<todo_id>", methods=["DELETE"])
def delete_todo(todo_id):
    todos = get_collection()
    todos.remove(ObjectId(todo_id))
    return make_json_response({"message": "OK"})


def get_collection():
    conn = pymongo.Connection("localhost:27017", **app.conn_args)
    return conn[app.db_name].todos


if __name__ == "__main__":
    import optparse

    parser = optparse.OptionParser()
    parser.add_option("-r", "--replicaset", dest="replicaset", help="Define replicaset name to connect to.")

    options, args = parser.parse_args()

    if options.replicaset is not None:
        app.conn_args = {"replicaset": options.replicaset, "slave_okay": True}
    else:
        app.conn_args = {}

    app.db_name = "todos_prod"
    app.run(host="0.0.0.0")