Skip to content

Commit 5a5c306

Browse files
committed
fix plan regulation group assocation saving
1 parent da19097 commit 5a5c306

File tree

2 files changed

+11
-25
lines changed

2 files changed

+11
-25
lines changed

arho_feature_template/core/plan_manager.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def save_plan(plan_data: Plan) -> QgsFeature:
230230
for regulation_group in plan_data.general_regulations:
231231
plan_id = plan_feature["id"]
232232
regulation_group_feature = save_regulation_group(regulation_group, plan_id)
233-
save_regulation_group_association(regulation_group_feature["id"], plan_id=plan_id)
233+
save_regulation_group_association(regulation_group_feature["id"], PlanLayer.name, plan_id)
234234

235235
return plan_feature
236236

@@ -291,13 +291,11 @@ def save_regulation_group(regulation_group: RegulationGroup, plan_id: str | None
291291
return feature
292292

293293

294-
def save_regulation_group_association(
295-
regulation_group_id: str, layer_name: str | None = None, feature_id: str | None = None, plan_id: str | None = None
296-
) -> QgsFeature:
297-
feature = RegulationGroupAssociationLayer.feature_from(regulation_group_id, layer_name, feature_id, plan_id)
294+
def save_regulation_group_association(regulation_group_id: str, layer_name: str, feature_id: str) -> QgsFeature:
295+
feature = RegulationGroupAssociationLayer.feature_from(regulation_group_id, layer_name, feature_id)
298296
layer = RegulationGroupAssociationLayer.get_from_project()
299297

300-
_save_feature(feature=feature, layer=layer, id_=None, edit_text="")
298+
_save_feature(feature=feature, layer=layer, id_=None, edit_text="Kaavamääräysryhmän assosiaation lisäys")
301299

302300
return feature
303301

arho_feature_template/project/layers/plan_layers.py

+7-19
Original file line numberDiff line numberDiff line change
@@ -161,33 +161,21 @@ class RegulationGroupAssociationLayer(AbstractPlanLayer):
161161
OtherPointLayer.name: "other_point_id",
162162
LandUseAreaLayer.name: "land_use_area_id",
163163
LineLayer.name: "line_id",
164+
PlanLayer.name: "plan_id",
164165
}
165166

166167
@classmethod
167-
def feature_from(
168-
cls,
169-
regulation_group_id: str | None,
170-
layer_name: str | None = None,
171-
feature_id: str | None = None,
172-
plan_id: str | None = None,
173-
) -> QgsFeature:
168+
def feature_from(cls, regulation_group_id: str, layer_name: str, feature_id: str) -> QgsFeature:
174169
layer = cls.get_from_project()
175170

176171
feature = QgsVectorLayerUtils.createFeature(layer)
177172
feature["plan_regulation_group_id"] = regulation_group_id
178173

179-
if layer_name:
180-
if feature_id is None:
181-
msg = "Plan feature ID must be provided to create association for regulation group and plan feature."
182-
raise ValueError(msg)
183-
attribute = cls.layer_name_to_attribute_map[layer_name]
184-
feature[attribute] = feature_id
185-
186-
feature["plan_id"] = (
187-
plan_id
188-
if plan_id
189-
else QgsExpressionContextUtils.projectScope(QgsProject.instance()).variable("active_plan_id")
190-
)
174+
attribute = cls.layer_name_to_attribute_map.get(layer_name)
175+
if not attribute:
176+
msg = f"Unrecognized layer name given for saving regulation group association: {layer_name}"
177+
raise ValueError(msg)
178+
feature[attribute] = feature_id
191179

192180
return feature
193181

0 commit comments

Comments
 (0)