@@ -573,20 +573,36 @@ def save_regulation_group(regulation_group: RegulationGroup, plan_id: str | None
573
573
feature = RegulationGroupLayer .feature_from_model (regulation_group , plan_id )
574
574
layer = RegulationGroupLayer .get_from_project ()
575
575
576
+ editing = regulation_group .id_ is not None
576
577
_save_feature (
577
578
feature = feature ,
578
579
layer = layer ,
579
580
id_ = regulation_group .id_ ,
580
- edit_text = "Kaavamääräysryhmän lisäys " if regulation_group . id_ is None else "Kaavamääräysryhmän muokkaus " ,
581
+ edit_text = "Kaavamääräysryhmän muokkaus " if editing else "Kaavamääräysryhmän lisäys " ,
581
582
)
582
583
583
- # Handle regulations
584
+ if editing :
585
+ # Check for regulations to be deleted
586
+ regulation_layer = PlanRegulationLayer .get_from_project ()
587
+ for reg_feature in PlanRegulationLayer .get_regulations_to_delete (
588
+ regulation_group .regulations , regulation_group
589
+ ):
590
+ _delete_feature (reg_feature , regulation_layer , "Kaavamääräyksen poisto" )
591
+
592
+ # Check for propositions to be deleted
593
+ proposition_layer = PlanPropositionLayer .get_from_project ()
594
+ for prop_feature in PlanPropositionLayer .get_propositions_to_delete (
595
+ regulation_group .propositions , regulation_group
596
+ ):
597
+ _delete_feature (prop_feature , proposition_layer , "Kaavasuosituksen poisto" )
598
+
599
+ # Save regulations
584
600
if regulation_group .regulations :
585
601
for regulation in regulation_group .regulations :
586
602
regulation .regulation_group_id_ = feature ["id" ] # Updating regulation group ID
587
603
save_regulation (regulation )
588
604
589
- # Handle propositions
605
+ # Save propositions
590
606
if regulation_group .propositions :
591
607
for proposition in regulation_group .propositions :
592
608
proposition .regulation_group_id_ = feature ["id" ] # Updating regulation group ID
@@ -602,13 +618,13 @@ def delete_regulation_group(regulation_group: RegulationGroup, plan_id: str | No
602
618
feature = RegulationGroupLayer .feature_from_model (regulation_group , plan_id )
603
619
layer = RegulationGroupLayer .get_from_project ()
604
620
605
- # # Handle regulations
606
- # for regulation in regulation_group.regulations:
607
- # delete_regulation(regulation)
621
+ # Delete regulations
622
+ for regulation in regulation_group .regulations :
623
+ delete_regulation (regulation )
608
624
609
- # # Handle propositions
610
- # for proposition in regulation_group.propositions:
611
- # delete_proposition(proposition)
625
+ # Delete propositions
626
+ for proposition in regulation_group .propositions :
627
+ delete_proposition (proposition )
612
628
613
629
_delete_feature (feature , layer , "Kaavamääräysryhmän poisto" )
614
630
0 commit comments