pas.data_import

Attributes

T

P

EXPECTED_HEADERS

Classes

Row

Base class for protocol classes.

ImportFile

Provides a unified interface for both CSV and Excel files.

HeaderValidationResult

Functions

preprocess_headers(→ list[str])

Helper function to process headers using rename mapping.

preprocess_csv_headers(→ _typeshed.StrOrBytesPath)

Preprocesses a CSV file to rename specific headers to avoid issues

validate_headers(→ HeaderValidationResult)

preprocess_excel_headers(→ _typeshed.StrOrBytesPath)

Preprocess Excel headers using a context manager for temporary file

match_expected_headers_or_fail(→ None)

with_open_excel_or_csv(...)

Decorator to handle opening and parsing import files.

import_commissions(→ None)

Imports all data from commission file.

Module Contents

pas.data_import.T[source]
pas.data_import.P[source]
class pas.data_import.Row[source]

Bases: Protocol

Base class for protocol classes.

Protocol classes are defined as:

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).

For example:

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:

class GenProto(Protocol[T]):
    def meth(self) -> T:
        ...
adress_anrede: str[source]
akademischer_titel: str[source]
anrede: str[source]
austritt_kommission: str[source]
bemerkungen: str[source]
beruf: str[source]
brief_anrede: str[source]
burgerort: str[source]
count: str[source]
e_mail_1: str[source]
e_mail_2: str[source]
eintritt_kommission: str[source]
fraktion: str[source]
geburtsdatum: str[source]
geschlecht: str[source]
id: str[source]
index: str[source]
nachname: str[source]
partei: str[source]
personalnummer: str[source]
privat_adresse: str[source]
privat_adresszusatz: str[source]
privat_ort: str[source]
privat_plz: str[source]
rolle_kommission: str[source]
rownumber: int[source]
spedition_kr_vorlagen: str[source]
telefon_geschaft: str[source]
telefon_mobile: str[source]
telefon_privat: str[source]
versand_adresse: str[source]
versand_adresszusatz: str[source]
versand_ort: str[source]
versand_plz: str[source]
versandart: str[source]
vertragsnummer: str[source]
vorname: str[source]
wahlkreis: str[source]
webseite: str[source]
zusatzinformationen: str[source]
pas.data_import.EXPECTED_HEADERS = ['adress_anrede', 'akademischer_titel', 'anrede', 'austritt_kommission', 'bemerkungen', 'beruf',...[source]
class pas.data_import.ImportFile(file: BinaryIO)[source]

Provides a unified interface for both CSV and Excel files.

ENCODINGS = ['utf-8', 'iso-8859-1'][source]
file[source]
rows: list[Any] = [][source]
_detect_type() None[source]

Detect if file is CSV or Excel based on content.

_parse() None[source]

Parse the file contents based on detected type.

_parse_csv() None[source]
_parse_excel() None[source]

Parse the file contents for excel files.

__enter__() Self[source]
__exit__(exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None) None[source]
pas.data_import.preprocess_headers(headers: list[str], header_renames: dict[str, str]) list[str][source]

Helper function to process headers using rename mapping.

pas.data_import.preprocess_csv_headers(csv_path_abs: _typeshed.StrOrBytesPath, expected: list[str] | None = None) _typeshed.StrOrBytesPath[source]

Preprocesses a CSV file to rename specific headers to avoid issues with the CSV parser. Creates a temporary file with the modified headers. Renames:

“1. E-Mail” to “E_Mail_1” “2. E-Mail” to “E_Mail_2”

Returns:

Path to the temporary CSV file with preprocessed headers.

class pas.data_import.HeaderValidationResult[source]
is_valid: bool[source]
missing_headers: list[str][source]
unexpected_headers: list[str][source]
original_headers: list[str][source]
pas.data_import.validate_headers(current_headers: list[str], expected_headers: list[str]) HeaderValidationResult[source]
pas.data_import.preprocess_excel_headers(excel_path: _typeshed.StrOrBytesPath, expected: list[str] | None = None) _typeshed.StrOrBytesPath[source]

Preprocess Excel headers using a context manager for temporary file handling.

Args:

excel_path: Path to the input Excel file expected: Optional list of expected headers to validate against

Returns:

Path to the processed temporary file

Raises:

Exception: If header processing or validation fails

pas.data_import.match_expected_headers_or_fail(expected: Any, header_row: Any) None[source]
pas.data_import.with_open_excel_or_csv(func: collections.abc.Callable[Ellipsis, T]) collections.abc.Callable[Ellipsis, T][source]

Decorator to handle opening and parsing import files. Handles both CSV and Excel files, preprocessing headers as needed.

pas.data_import.import_commissions(import_file: ImportFile, session: sqlalchemy.orm.Session, commission_file_abs_path: str, **kwargs: Any) None[source]

Imports all data from commission file.