def update_requirements()

in project/paperbench/paperbench/gui/app.py [0:0]


def update_requirements():
    """Updates the requirements for the given `node_id`."""
    with lock:  # Use lock to support concurrent requests
        data: dict = sanitize_request_data(request.json)
        node_id = data.get("node_id")
        new_requirements = data.get("requirements")

        try:
            with open(app.config["PATH_TO_PAPER"] / app.config["RUBRIC_FILE_NAME"], "r") as f:
                rubric = json.load(f)

            old_root = app.config["NODE_TYPE"].from_dict(rubric)
            old_node = old_root.find(node_id)
            new_node = old_node.set_requirements(new_requirements)
            new_root = old_root.replace(node_id, new_node)

            with open(app.config["PATH_TO_PAPER"] / app.config["RUBRIC_FILE_NAME"], "w") as f:
                json.dump(new_root.to_dict(), f, indent=4)

            return jsonify({"status": "success"})
        except Exception as e:
            return jsonify(
                {
                    "status": "error",
                    "message": f"Error updating requirements for node {node_id}: {str(e)}",
                }
            )