combobox retrieval

This commit is contained in:
2026-05-12 16:30:03 +02:00
parent 4befb8e3c5
commit 8b3eb63f62

View File

@@ -53,6 +53,7 @@ QSS = """
border: 1px dashed #cbd5e1;
}
"""
DROPDOWN_DEFAULT: str = "--- Bitte wählen ---"
class CompanyForm_Search(QWidget):
@@ -271,6 +272,20 @@ class FormFieldType(enum.StrEnum):
DYNAMIC_LIST = enum.auto()
@dc.dataclass(slots=True)
class DropdownOption:
label: str
_data: dc.InitVar[Any | None] = None
data: Any = dc.field(init=False)
def __post_init__(
self,
_data: Any | None,
) -> None:
if _data is None:
self.data = self.label
@dc.dataclass(slots=True)
class FormField:
label: str
@@ -278,14 +293,18 @@ class FormField:
children: Sequence[FormField] = dc.field(default_factory=list)
parent: FormField | None = None
required: bool = False
placeholder: str | None = None
fill_value: str | None = None
placeholder: str = ""
fill_value: str = ""
readonly: bool = False
options: Sequence[str] | None = None
options: dc.InitVar[Sequence[tuple[str, Any]]] = tuple()
dropdown_options: Sequence[DropdownOption] = dc.field(default=tuple(), init=False)
key: str = ""
tooltip: str = ""
def __post_init__(self) -> None:
def __post_init__(
self,
options: Sequence[tuple[str, Any]],
) -> None:
if not self.key:
self.key = str(uuid.uuid4())
@@ -295,25 +314,15 @@ class FormField:
if self.required:
self.label += "*"
if self.type is FormFieldType.DROPDOWN and self.options is None:
if self.type is FormFieldType.DROPDOWN and not options:
raise ValueError("Invalid field definition: Dropdown requires options")
elif self.type is FormFieldType.DROPDOWN:
self.dropdown_options = tuple(DropdownOption(op[0], op[1]) for op in options)
for child in self.children:
child.parent = self
@dc.dataclass(slots=True)
class FormFieldDynList:
label: str
fields: Sequence[FormField]
# @dc.dataclass(slots=True)
# class FormFieldGroup:
# label: str | None
# fields: Sequence[FormField] | FormFieldDynList
class WidgetRegistryEntry(TypedDict):
widget: QWidget
form_field: FormField
@@ -427,6 +436,7 @@ FORM_FIELDS_CONTACT_PERSON = [
FormField(
"Name Unternehmen/Netzwerkpartner (pre-filled von Suche)",
FormFieldType.TEXT,
key="t1",
required=False,
placeholder="Text wird nach gewähltem Unternehmen angezeigt",
readonly=True,
@@ -434,6 +444,7 @@ FORM_FIELDS_CONTACT_PERSON = [
FormField(
"Titel",
FormFieldType.TEXT,
key="t2",
required=False,
tooltip=(
"* nur wenn anrufende Person oder kontaktaufnehmende Person "
@@ -443,41 +454,49 @@ FORM_FIELDS_CONTACT_PERSON = [
FormField(
"Anrede_Anschrift",
FormFieldType.TEXT,
key="t3",
required=True,
),
FormField(
"Name",
FormFieldType.TEXT,
key="t4",
required=True,
),
FormField(
"Vorname",
FormFieldType.TEXT,
key="t5",
required=False,
),
FormField(
"Festnetznummer",
FormFieldType.TEXT,
key="t6",
required=False,
),
FormField(
"Mobilfunknummer",
FormFieldType.TEXT,
key="t7",
required=False,
),
FormField(
"E-Mail",
FormFieldType.TEXT,
key="t8",
required=False,
),
FormField(
"Funktion/Beziehung zur beratenden Person",
FormFieldType.TEXT,
key="t9",
required=False,
),
FormField(
"Adresse",
FormFieldType.LONGTEXT,
key="t10",
required=False,
),
]
@@ -520,28 +539,28 @@ FORM_FIELDS_MASTER_DATA = [
"Herkunftsland",
FormFieldType.DROPDOWN,
required=True,
options=["LÄNDERLISTE NOCH ZU ERGÄNZEN"],
options=[("LÄNDERLISTE NOCH ZU ERGÄNZEN", None)],
tooltip=("* Wichtig zu erfragen aufgrund eventueller EU-Freizügigkeitsregelung"),
),
FormField(
"Staatsangehörigkeit",
FormFieldType.DROPDOWN,
required=False,
options=["LÄNDERLISTE NOCH ZU ERGÄNZEN"],
options=[("LÄNDERLISTE NOCH ZU ERGÄNZEN", None)],
tooltip=("* Wichtig zu erfragen aufgrund eventueller EU-Freizügigkeitsregelung"),
),
FormField(
"Rückkehrer",
FormFieldType.DROPDOWN,
required=False,
options=["ja", "nein"],
options=[("ja", None), ("nein", None)],
tooltip=("* Wichtig zu erfragen aufgrund eventueller EU-Freizügigkeitsregelung"),
),
FormField(
"Wo befindet sich die Person?",
FormFieldType.DROPDOWN,
required=True,
options=["Inland", "Ausland EU/EWR", "Ausland Drittstaat"],
options=[("Inland", None), ("Ausland EU/EWR", None), ("Ausland Drittstaat", None)],
),
FormField(
"Straße",
@@ -567,7 +586,7 @@ FORM_FIELDS_MASTER_DATA = [
"Bundesland",
FormFieldType.DROPDOWN,
required=False,
options=["BUNDESLÄNDER NOCH ZU ERGÄNZEN"],
options=[("BUNDESLÄNDER NOCH ZU ERGÄNZEN", None)],
tooltip=(
"nur wenn Inland angegeben und die Angabe zieht es in keine Dokumente "
"rüber! Liste Bundesländer verwenden"
@@ -603,7 +622,7 @@ FORM_FIELDS_MASTER_DATA = [
"Anzahl Kinder",
FormFieldType.DROPDOWN,
required=False,
options=[str(x) for x in range(11)],
options=[(str(x), None) for x in range(11)],
tooltip="* Wichtig zu erfragen aufgrund Lebensunterhaltssicherung",
),
]
@@ -613,27 +632,31 @@ FORM_FIELDS_ADDITIONAL_DATA = [
"Deutsch als Kommunikationssprache",
FormFieldType.DROPDOWN,
required=False,
options=["nein", "ja, als Muttersprache", "ja, als Fremdsprache"],
options=[
("nein", None),
("ja, als Muttersprache", None),
("ja, als Fremdsprache", None),
],
),
FormField(
"Aufenthaltstitel",
FormFieldType.DROPDOWN,
required=False,
options=[
"anerkannter Flüchtling §§ 22 - 26 AufenthG",
"Aufenthaltsgestattung §55 AufenthG",
"Blaue Karte EU § 18g AufenthG",
"BüMA (Bescheinigung über Meldung als Asylsuchender)",
"Duldung § 60 AufenthG",
"bisher kein Aufenthaltstitel",
"Deutscher",
"familiäre Gründe §§ 27 - 36 AufenthG",
"Niederlassungserlaubnis §9 AufenthG",
"Staatsbürger EUR/EWR/CH",
"Aufenthalt für Ausbildung §§ 16 - 17 AufenthG",
"Aufenthalt für Erwerbstätigkeit §§ 18- 21 AufenthG",
"Chancenaufenthaltsrecht §104c AufenthG",
"Sonstiges",
("anerkannter Flüchtling §§ 22 - 26 AufenthG", None),
("Aufenthaltsgestattung §55 AufenthG", None),
("Blaue Karte EU § 18g AufenthG", None),
("BüMA (Bescheinigung über Meldung als Asylsuchender)", None),
("Duldung § 60 AufenthG", None),
("bisher kein Aufenthaltstitel", None),
("Deutscher", None),
("familiäre Gründe §§ 27 - 36 AufenthG", None),
("Niederlassungserlaubnis §9 AufenthG", None),
("Staatsbürger EUR/EWR/CH", None),
("Aufenthalt für Ausbildung §§ 16 - 17 AufenthG", None),
("Aufenthalt für Erwerbstätigkeit §§ 18- 21 AufenthG", None),
("Chancenaufenthaltsrecht §104c AufenthG", None),
("Sonstiges", None),
],
tooltip="sofern nicht bekannt, unbedingt einfordern",
),
@@ -647,14 +670,14 @@ FORM_FIELDS_ADDITIONAL_DATA = [
FormFieldType.DROPDOWN,
required=False,
options=[
"Arbeitslos",
"Ausbildung/Qualifizierung Inland",
"geringfügig beschäftigt",
"in Anstellung Inland",
"selbstständig Inland",
"Ausbildung/Qualifizierung Ausland",
"in Anstellung Ausland",
"selbstständig Ausland",
("Arbeitslos", None),
("Ausbildung/Qualifizierung Inland", None),
("geringfügig beschäftigt", None),
("in Anstellung Inland", None),
("selbstständig Inland", None),
("Ausbildung/Qualifizierung Ausland", None),
("in Anstellung Ausland", None),
("selbstständig Ausland", None),
],
),
FormField(
@@ -662,13 +685,13 @@ FORM_FIELDS_ADDITIONAL_DATA = [
FormFieldType.DROPDOWN,
required=False,
options=[
"bei keiner",
"Jobcenter mit Leistungsbezug",
"Jobcenter ohne Leistungsbezug",
"Sozialamt mit Leistungsbezug",
"Sozialamt ohne Leistungsbezug",
"Agentur für Arbeit mit Leistungsbezug",
"Agentur für Arbeit ohne Leistungsbezug",
("bei keiner", None),
("Jobcenter mit Leistungsbezug", None),
("Jobcenter ohne Leistungsbezug", None),
("Sozialamt mit Leistungsbezug", None),
("Sozialamt ohne Leistungsbezug", None),
("Agentur für Arbeit mit Leistungsbezug", None),
("Agentur für Arbeit ohne Leistungsbezug", None),
],
),
]
@@ -698,7 +721,7 @@ FORM_FIELDS_SCHOOL = [
"Land",
FormFieldType.DROPDOWN,
required=False,
options=["LÄNDERLISTE ERGÄNZEN"],
options=[("LÄNDERLISTE ERGÄNZEN", None)],
),
FormField(
"Abschlussjahr",
@@ -750,7 +773,7 @@ FORM_FIELDS_HIGHER_EDUCATION = [
"Land",
FormFieldType.DROPDOWN,
required=False,
options=["LÄNDERLISTE ERGÄNZEN"],
options=[("LÄNDERLISTE ERGÄNZEN", None)],
),
FormField(
"Ort",
@@ -775,7 +798,7 @@ FORM_FIELDS_WORK_EXPERIENCE = [
"Branche",
FormFieldType.DROPDOWN,
required=False,
options=["DROPDOWN-LISTE AN ANDERER STELLE DEFINIERT"],
options=[("DROPDOWN-LISTE AN ANDERER STELLE DEFINIERT", None)],
),
FormField(
"Berufsbezeichnung/Tätigkeit",
@@ -787,16 +810,16 @@ FORM_FIELDS_WORK_EXPERIENCE = [
FormFieldType.DROPDOWN,
required=False,
options=[
"Auszubildender",
"Fachkraft",
"Hilfskraft",
"Akademiker",
"Führungskraft",
"Praktikant",
"FSJ/BFD",
"Elternzeit",
"Sabbatical",
"Sonstiges",
("Auszubildender", None),
("Fachkraft", None),
("Hilfskraft", None),
("Akademiker", None),
("Führungskraft", None),
("Praktikant", None),
("FSJ/BFD", None),
("Elternzeit", None),
("Sabbatical", None),
("Sonstiges", None),
],
),
FormField(
@@ -808,7 +831,7 @@ FORM_FIELDS_WORK_EXPERIENCE = [
"Land",
FormFieldType.DROPDOWN,
required=False,
options=["LÄNDERLISTE ERGÄNZEN"],
options=[("LÄNDERLISTE ERGÄNZEN", None)],
),
FormField(
"Zeitspanne (von ... bis ...)",
@@ -820,9 +843,9 @@ FORM_FIELDS_WORK_EXPERIENCE = [
FormFieldType.DROPDOWN,
required=False,
options=[
"Vollzeit",
"Teilzeit",
"Sonstiges",
("Vollzeit", None),
("Teilzeit", None),
("Sonstiges", None),
],
tooltip="Minijob, Praktikum, Wehrdienst, soziale Dienste",
),
@@ -844,12 +867,12 @@ FORM_FIELDS_LANGUAGES = [
FormFieldType.DROPDOWN,
required=False,
options=[
"A1",
"A2",
"B1",
"B2",
"C1",
"C2",
("A1", None),
("A2", None),
("B1", None),
("B2", None),
("C1", None),
("C2", None),
],
),
FormField(
@@ -857,8 +880,8 @@ FORM_FIELDS_LANGUAGES = [
FormFieldType.DROPDOWN,
required=False,
options=[
"vorhanden",
"nicht vorhanden",
("vorhanden", None),
("nicht vorhanden", None),
],
),
FormField(
@@ -883,9 +906,9 @@ FORM_FIELDS = [
FormField(
"Projektrelevanz",
FormFieldType.DROPDOWN,
key="projektrelevanz",
required=True,
options=["ja", "nein"],
fill_value="nein",
options=[("ja", None), ("nein", None)],
),
],
),
@@ -1025,9 +1048,11 @@ def _build_ui_recursively(
case FormFieldType.DROPDOWN:
widget = QComboBox()
assert field.options
widget.addItem("--- Bitte wählen ---")
widget.addItems(field.options)
assert field.dropdown_options
widget.addItem(DROPDOWN_DEFAULT, None)
for option in field.dropdown_options:
widget.addItem(option.label, option.data)
if field.placeholder:
widget.setPlaceholderText(field.placeholder)
if field.fill_value:
@@ -1242,6 +1267,9 @@ class AutoForm(QWidget):
elif isinstance(widget, QPlainTextEdit):
if widget.toPlainText().strip():
continue
elif isinstance(widget, QComboBox):
if widget.currentData() is not None:
continue
error = form_field.label.replace("*", "").replace(":", "")
if form_field.parent is not None:
@@ -1286,6 +1314,8 @@ class AutoForm(QWidget):
raw_data = {}
for key, registry_entry in self.widget_registry.items():
value: Any | None = None
widget = registry_entry["widget"]
if isinstance(widget, QLineEdit):
value = widget.text()
@@ -1295,15 +1325,13 @@ class AutoForm(QWidget):
qt_date = widget.date()
value = qt_date.toPython()
elif isinstance(widget, QComboBox):
# TODO add
...
# value = widget.toPlainText()
elif isinstance(widget, DynamicListWidget): # Unser Custom Widget
value = widget.currentData()
elif isinstance(widget, DynamicListWidget):
# TODO add method
# value = widget.get_data()
# this should be a list: each dynamic list contains a list
# of such dictionaries
value = "test"
else:
value = None
_insert_nested(raw_data, key.split("."), value)