It's possible to set the configuration from PyQGIS although it has been a bit annoying to look at the C code to find the keys to write in the QGIS project file (https://github.com/qgis/QGIS/blob/9a0a1297c2e585cdbc3dbeeb64f5792024a451f9/src/app/qgsprojectproperties.cpp#L1479)
You can find below a recipe. After running it, you will be able to see if it works fine by opening the "Project properties | QGIS Server" panel
Limit of the recipe: we didn't try to catch error when the layer name in the config does not match the layers in the QGIS project
vectorLayers = {layer.id(): layer.name() for layer in QgsProject.instance().mapLayers().values() if isinstance(layer, QgsVectorLayer)}
wfsLayersConfig = [
{
"name": "your layer name 1",
"published": True,
"precision": 8,
"Update": True,
"Insert": False,
"Delete": True
},
{
"name": "your layer name 2",
"published": False,
"precision": 8,
"Update": False,
"Insert": True,
"Delete": False
}
]
# To join by name as a key instead of identifier
# Weak but to be generic, more simple to use layer name
# whereas layers identifiers hidden
vectorLayersKeyValReversed = {v: k for k, v in vectorLayers.items()}
# To set if published
QgsProject.instance().writeEntry( "WFSLayers" , "/", [vectorLayersKeyValReversed[l['name']] for l in wfsLayersConfig if l["published"]]);
# Set precision (need to loop as the xml tag is the layer identifier)
[QgsProject.instance().writeEntry("WFSLayersPrecision", "/" + vectorLayersKeyValReversed[l['name']], l["precision"]) for l in wfsLayersConfig]
# Set Update
QgsProject.instance().writeEntry( "WFSTLayers" , "Update", [vectorLayersKeyValReversed[l['name']] for l in wfsLayersConfig if l["Update"]]);
# Set Insert
QgsProject.instance().writeEntry( "WFSTLayers" , "Insert", [vectorLayersKeyValReversed[l['name']] for l in wfsLayersConfig if l["Insert"]]);
# Set Delete
QgsProject.instance().writeEntry( "WFSTLayers" , "Delete", [vectorLayersKeyValReversed[l['name']] for l in wfsLayersConfig if l["Delete"]]);
QgsProject.instance().write()