pas.data_import
Attributes
Classes
Base class for protocol classes. |
|
Provides a unified interface for both CSV and Excel files. |
|
Functions
|
Helper function to process headers using rename mapping. |
|
Preprocesses a CSV file to rename specific headers to avoid issues |
|
|
|
Preprocess Excel headers using a context manager for temporary file |
|
|
Decorator to handle opening and parsing import files. |
|
|
Imports all data from commission file. |
Module Contents
- 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: ...
- 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.
- 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.
- 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.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.