From 3e02db5bf91c337fd4394d891094ba27bbdd728e Mon Sep 17 00:00:00 2001 From: Niko Aarnio Date: Tue, 25 Feb 2025 09:40:08 +0200 Subject: [PATCH 1/2] fix short name checks for regulation groups --- arho_feature_template/gui/dialogs/plan_feature_form.py | 7 ++++++- .../gui/dialogs/plan_regulation_group_form.py | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/arho_feature_template/gui/dialogs/plan_feature_form.py b/arho_feature_template/gui/dialogs/plan_feature_form.py index 580d7d3..7b6f526 100644 --- a/arho_feature_template/gui/dialogs/plan_feature_form.py +++ b/arho_feature_template/gui/dialogs/plan_feature_form.py @@ -114,7 +114,12 @@ def _check_regulation_group_short_names(self) -> bool: if not short_name: continue - if short_name in self.existing_group_short_names: + if ( + not ( + reg_group_widget.regulation_group.id_ and short_name == reg_group_widget.regulation_group.short_name + ) + and short_name in self.existing_group_short_names + ): existing_names.add(short_name) if short_name in seen_names: duplicate_names.add(short_name) diff --git a/arho_feature_template/gui/dialogs/plan_regulation_group_form.py b/arho_feature_template/gui/dialogs/plan_regulation_group_form.py index cd234ae..969d025 100644 --- a/arho_feature_template/gui/dialogs/plan_regulation_group_form.py +++ b/arho_feature_template/gui/dialogs/plan_regulation_group_form.py @@ -146,7 +146,13 @@ def _initalize_regulation_from_config(self, config: RegulationConfig, parent: QT def _check_short_name(self) -> bool: short_name = self.short_name.text() - if short_name and short_name in self.existing_group_short_names: + + if not short_name: + return True + if ( + not (self.regulation_group.id_ and short_name == self.regulation_group.short_name) + and short_name in self.existing_group_short_names + ): msg = f"Kaavamääräysryhmä lyhyellä nimellä '{short_name}' on jo olemassa." QMessageBox.critical(self, "Virhe", msg) return False From 9c8d8d4d331391060b4391c751b820de4493900c Mon Sep 17 00:00:00 2001 From: Niko Aarnio Date: Thu, 27 Feb 2025 09:25:09 +0200 Subject: [PATCH 2/2] clarify regulation group short name checks --- .../gui/dialogs/plan_feature_form.py | 29 ++++++++++--------- .../gui/dialogs/plan_regulation_group_form.py | 5 +++- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/arho_feature_template/gui/dialogs/plan_feature_form.py b/arho_feature_template/gui/dialogs/plan_feature_form.py index 7b6f526..a6d7358 100644 --- a/arho_feature_template/gui/dialogs/plan_feature_form.py +++ b/arho_feature_template/gui/dialogs/plan_feature_form.py @@ -109,39 +109,42 @@ def _check_regulation_group_short_names(self) -> bool: existing_names = set() duplicate_names = set() + def _is_existing_model_with_unmodified_short_name(model: RegulationGroup, short_name: str) -> bool: + return bool(model.id_ and short_name == model.short_name) + + def _format_names(names, last_item_conjucation: str = "ja") -> str: + names = list(names) + formatted_names = ", ".join(f"'{name}'" for name in names[:-1]) + formatted_names += f" {last_item_conjucation} " if len(names) > 1 else "" + formatted_names += f"'{names[-1]}'" if names else "" + return formatted_names + for reg_group_widget in self.regulation_group_widgets: short_name = reg_group_widget.short_name.text() if not short_name: continue if ( - not ( - reg_group_widget.regulation_group.id_ and short_name == reg_group_widget.regulation_group.short_name - ) + not _is_existing_model_with_unmodified_short_name(reg_group_widget.regulation_group, short_name) and short_name in self.existing_group_short_names ): existing_names.add(short_name) + if short_name in seen_names: duplicate_names.add(short_name) - seen_names.add(short_name) - def format_names(names, last_item_conjucation: str = "ja"): - names = list(names) - formatted_names = ", ".join(f"'{name}'" for name in names[:-1]) - formatted_names += f" {last_item_conjucation} " if len(names) > 1 else "" - formatted_names += f"'{names[-1]}'" if names else "" - return formatted_names + seen_names.add(short_name) if existing_names: if len(existing_names) == 1: - msg = f"Kaavamääräysryhmä lyhyellä nimellä {format_names(existing_names)} on jo olemassa." + msg = f"Kaavamääräysryhmä lyhyellä nimellä {_format_names(existing_names)} on jo olemassa." else: - msg = f"Kaavamääräysryhmät lyhyillä nimillä {format_names(existing_names)} ovat jo olemassa." + msg = f"Kaavamääräysryhmät lyhyillä nimillä {_format_names(existing_names)} ovat jo olemassa." QMessageBox.critical(self, "Virhe", msg) return False if duplicate_names: - msg = f"Lomakkeella on useita kaavamääräysryhmiä, joilla on lyhyt nimi {format_names(duplicate_names, 'tai')}." + msg = f"Lomakkeella on useita kaavamääräysryhmiä, joilla on lyhyt nimi {_format_names(duplicate_names, 'tai')}." QMessageBox.critical(self, "Virhe", msg) return False diff --git a/arho_feature_template/gui/dialogs/plan_regulation_group_form.py b/arho_feature_template/gui/dialogs/plan_regulation_group_form.py index 969d025..78838ee 100644 --- a/arho_feature_template/gui/dialogs/plan_regulation_group_form.py +++ b/arho_feature_template/gui/dialogs/plan_regulation_group_form.py @@ -147,10 +147,13 @@ def _initalize_regulation_from_config(self, config: RegulationConfig, parent: QT def _check_short_name(self) -> bool: short_name = self.short_name.text() + def _is_existing_model_with_unmodified_short_name(model: RegulationGroup, short_name: str) -> bool: + return bool(model.id_ and short_name == model.short_name) + if not short_name: return True if ( - not (self.regulation_group.id_ and short_name == self.regulation_group.short_name) + not _is_existing_model_with_unmodified_short_name(self.regulation_group, short_name) and short_name in self.existing_group_short_names ): msg = f"Kaavamääräysryhmä lyhyellä nimellä '{short_name}' on jo olemassa."