Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Korjaa olemassa olevien kaavamääräysryhmien lisääminen #204

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions arho_feature_template/gui/dialogs/plan_feature_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,34 +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"'<b>{name}</b>'" for name in names[:-1])
formatted_names += f" {last_item_conjucation} " if len(names) > 1 else ""
formatted_names += f"'<b>{names[-1]}</b>'" 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 short_name in self.existing_group_short_names:
if (
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"'<b>{name}</b>'" for name in names[:-1])
formatted_names += f" {last_item_conjucation} " if len(names) > 1 else ""
formatted_names += f"'<b>{names[-1]}</b>'" 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

Expand Down
11 changes: 10 additions & 1 deletion arho_feature_template/gui/dialogs/plan_regulation_group_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,16 @@ 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:

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 _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ä '<b>{short_name}</b>' on jo olemassa."
QMessageBox.critical(self, "Virhe", msg)
return False
Expand Down