generated from dopt-python/py311
127 lines
2.3 KiB
Python
127 lines
2.3 KiB
Python
# %%
|
|
import dataclasses as dc
|
|
import enum
|
|
import re
|
|
from collections.abc import Sequence
|
|
|
|
import babel
|
|
from PySide6.QtCore import QDate, Qt
|
|
|
|
|
|
# %%
|
|
@dc.dataclass(slots=True)
|
|
class CountryList:
|
|
iso_to_country: dict[str, str]
|
|
for_dropdown: Sequence[tuple[str, str]]
|
|
|
|
|
|
def get_country_list_german() -> CountryList:
|
|
locale = babel.Locale("de", "DE")
|
|
countries: list[tuple[str, str]] = []
|
|
iso_to_country: dict[str, str] = {}
|
|
|
|
for iso_code, country_name in locale.territories.items():
|
|
if len(iso_code) == 2 and not iso_code.isdigit():
|
|
countries.append((country_name, iso_code))
|
|
iso_to_country[iso_code] = country_name
|
|
|
|
countries.sort(key=lambda x: x[0])
|
|
|
|
return CountryList(
|
|
iso_to_country=iso_to_country,
|
|
for_dropdown=tuple(countries),
|
|
)
|
|
|
|
|
|
# %%
|
|
laender_liste
|
|
|
|
# %%
|
|
DYNAMIC_LIST_KEY_PATTERN = r"-\[(\d+)\]"
|
|
key = "Schulbildung-[12].7b8da0f7-7a0e-4f71-878a-85616099e849"
|
|
|
|
matches = re.search(DYNAMIC_LIST_KEY_PATTERN, key)
|
|
|
|
# %%
|
|
matches
|
|
|
|
# %%
|
|
matches.group(1)
|
|
|
|
|
|
# %%
|
|
class COUNTRY(enum.IntEnum):
|
|
DE = 1
|
|
FR = 2
|
|
CM = 3
|
|
|
|
|
|
class COUNTRY2(enum.Enum):
|
|
DE = 1
|
|
FR = 2
|
|
CM = 3
|
|
|
|
|
|
def give_value(t):
|
|
print(f"Wert ist: {t}")
|
|
|
|
|
|
give_value(COUNTRY.DE)
|
|
give_value(COUNTRY2.DE)
|
|
|
|
# %%
|
|
COUNTRY(10)
|
|
# %%
|
|
COUNTRY.DE
|
|
# %%
|
|
t_str = "asd.yxcxc.dfgjj.aasdsdsdsd.sdsdsdsd"
|
|
splitted = t_str.split(".")
|
|
part, rest = splitted[0], splitted[1:]
|
|
|
|
part
|
|
|
|
# %%
|
|
".".join([part] + rest)
|
|
|
|
# %%
|
|
|
|
|
|
class FormFieldType(enum.StrEnum):
|
|
TEXT = enum.auto()
|
|
LONGTEXT = enum.auto()
|
|
DATE = enum.auto()
|
|
DATETIME = enum.auto()
|
|
|
|
|
|
@dc.dataclass(slots=True)
|
|
class FormField:
|
|
key: str
|
|
label: str
|
|
type: FormFieldType
|
|
required: bool
|
|
|
|
def __post_init__(self) -> None:
|
|
self.label = self.label.strip()
|
|
if not self.label.endswith(":"):
|
|
self.label += ":"
|
|
if self.required:
|
|
self.label += "*"
|
|
|
|
|
|
# %%
|
|
FormField("name", "Projektbeschreibung", FormFieldType.LONGTEXT, required=True)
|
|
# %%
|
|
FormField("name", "Projektbeschreibung:", FormFieldType.LONGTEXT, required=True)
|
|
|
|
# %%
|
|
FormField("name", "Projektbeschreibung", FormFieldType.LONGTEXT, required=False)
|
|
# %%
|
|
FormField("name", "Projektbeschreibung:", FormFieldType.LONGTEXT, required=False)
|
|
# %%
|
|
addr.export()
|
|
# %%
|
|
set_date = QDate.fromString("26.07.2026", "dd.MM.yyyy")
|
|
|
|
# %%
|
|
Qt.Tet
|