generated from dopt-python/py311
document selection: add Pydantic models and tests for saving/loading
This commit is contained in:
+15
-82
@@ -100,12 +100,17 @@ from wce_crm.data_models import (
|
||||
Page_NewEntry_State,
|
||||
Session,
|
||||
set_page_state,
|
||||
translate_pydantic_errors,
|
||||
)
|
||||
from wce_crm.form_defs import (
|
||||
FormField,
|
||||
FormFieldType,
|
||||
)
|
||||
from wce_crm.gui_components.dialogs import (
|
||||
GUI_validation_error_handling,
|
||||
get_message_box,
|
||||
get_user_confirmation,
|
||||
pydantic_validation_error_handling,
|
||||
)
|
||||
from wce_crm.logging import (
|
||||
logger_custom_fields,
|
||||
logger_get_data,
|
||||
@@ -4984,7 +4989,7 @@ class Page_Consulting(QWidget):
|
||||
self.STATE.locked = True
|
||||
|
||||
if update_only:
|
||||
relevant_gui_states = [s for s in self.STATE.cons_sessions if not s.ist_geloescht]
|
||||
relevant_gui_states = [s for s in self.STATE.cons_sessions if not s.geloescht]
|
||||
rel_cons_session_states = [s for s in data.beratungen if s.geloescht is None]
|
||||
assert len(relevant_gui_states) == len(rel_cons_session_states)
|
||||
for gui_state, pydantic_state in zip(
|
||||
@@ -5097,7 +5102,7 @@ class Page_Consulting(QWidget):
|
||||
|
||||
for row in self.STATE.cons_sessions:
|
||||
logger_page_consulting.debug("[Consulting Page] Row state:\n%s", row)
|
||||
if row.beratung_id is None and row.ist_geloescht:
|
||||
if row.beratung_id is None and row.geloescht:
|
||||
logger_page_consulting.debug(
|
||||
(
|
||||
"[Consulting Page] Session which was never saved in the database "
|
||||
@@ -5110,7 +5115,7 @@ class Page_Consulting(QWidget):
|
||||
if timestamp_deleted is not None:
|
||||
# if process is deleted, all sessions must be marked as deleted
|
||||
timestamp_deleted_session = timestamp_deleted
|
||||
elif row.ist_geloescht:
|
||||
elif row.geloescht:
|
||||
timestamp_deleted_session = datetime.datetime.now(datetime.UTC)
|
||||
|
||||
cons_session_dict = dc.asdict(row)
|
||||
@@ -5596,9 +5601,11 @@ class Page_Consulting_ConsultingSession(QWidget):
|
||||
"Löschen bestätigen",
|
||||
"Soll der Eintrag wirklich gelöscht werden?",
|
||||
)
|
||||
if confirm:
|
||||
self.STATE.ist_geloescht = True
|
||||
self.delete_request.emit(self)
|
||||
if not confirm:
|
||||
return
|
||||
|
||||
self.STATE.geloescht = True
|
||||
self.delete_request.emit(self)
|
||||
|
||||
def _sync_state_to_GUI(
|
||||
self,
|
||||
@@ -5863,7 +5870,7 @@ class Page_Consulting_Table(QWidget):
|
||||
# states_to_show = [s for s in self.STATE.row_states if not s.ist_geloescht]
|
||||
# for row_state in states_to_show:
|
||||
for row_state in self.STATE.row_states:
|
||||
if not row_state.ist_geloescht:
|
||||
if not row_state.geloescht:
|
||||
self.add_row(row_state, True)
|
||||
|
||||
if section is None or section == "locking":
|
||||
@@ -6009,80 +6016,6 @@ def clear_layout(
|
||||
clear_layout(child.layout())
|
||||
|
||||
|
||||
def get_message_box(
|
||||
msg_type: QMessageBox.Icon,
|
||||
title: str,
|
||||
message: str,
|
||||
detailed_text: str | None = None,
|
||||
) -> QMessageBox:
|
||||
msg_box = QMessageBox()
|
||||
msg_box.setIcon(msg_type)
|
||||
msg_box.setWindowTitle(title)
|
||||
msg_box.setText(message)
|
||||
if detailed_text is not None:
|
||||
msg_box.setDetailedText(detailed_text)
|
||||
|
||||
return msg_box
|
||||
|
||||
|
||||
def get_user_confirmation(
|
||||
parent_widget: QWidget,
|
||||
title: str,
|
||||
message: str,
|
||||
) -> bool:
|
||||
response = QMessageBox.question(
|
||||
parent_widget,
|
||||
title,
|
||||
message,
|
||||
buttons=(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No),
|
||||
defaultButton=QMessageBox.StandardButton.No,
|
||||
)
|
||||
|
||||
if response == QMessageBox.StandardButton.Yes:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def pydantic_validation_error_handling(
|
||||
val_error: ValidationError,
|
||||
) -> None:
|
||||
error_texts: list[str] = []
|
||||
translated_errors = translate_pydantic_errors(val_error.errors())
|
||||
|
||||
for error in translated_errors:
|
||||
error_field = str(error["loc"][0])
|
||||
reason = error["msg"]
|
||||
path = " → ".join(error["loc"][:-1]) # type: ignore
|
||||
|
||||
error_texts.append(f"- {error_field}: {reason}, (Pfad: {path})")
|
||||
|
||||
msg_box = get_message_box(
|
||||
QMessageBox.Icon.Warning,
|
||||
"Fehler bei der Validierung der Eingabedaten",
|
||||
(
|
||||
"Bei der Validierung der Eingaben ist ein Fehler aufgetreten. Details "
|
||||
"sind unten angefügt."
|
||||
),
|
||||
"\n".join(error_texts),
|
||||
)
|
||||
msg_box.exec()
|
||||
|
||||
|
||||
def GUI_validation_error_handling(
|
||||
errors: list[str],
|
||||
) -> None:
|
||||
error_text = "Bitte füllen Sie die folgenden Pflichtfelder aus:\n\n▸ " + "\n▸ ".join(
|
||||
errors
|
||||
)
|
||||
msg_box = get_message_box(
|
||||
QMessageBox.Icon.Warning,
|
||||
"Fehlende oder fehlerhafte Angaben",
|
||||
error_text,
|
||||
)
|
||||
msg_box.exec()
|
||||
|
||||
|
||||
class _ModifyButton(QPushButton):
|
||||
modify_activated = Signal()
|
||||
modify_deactivated = Signal()
|
||||
|
||||
Reference in New Issue
Block a user