[32788f42] fix(list-generator): normalize CSV column names to support legacy headers like 'Vorname Kind' and 'Gruppe'
This commit is contained in:
@@ -5,10 +5,26 @@ from weasyprint import HTML
|
||||
import datetime
|
||||
|
||||
def generate_school_pdf(institution: str, date_info: str, list_type: str, students_csv_path: str, families_csv_path: str = None, output_dir: str = "/tmp") -> str:
|
||||
df = pd.read_csv(students_csv_path, sep=";")
|
||||
try:
|
||||
df = pd.read_csv(students_csv_path, sep=";", encoding="utf-8-sig")
|
||||
except Exception:
|
||||
df = pd.read_csv(students_csv_path, sep=";", encoding="latin1")
|
||||
df.columns = df.columns.str.strip()
|
||||
if "Klasse" not in df.columns:
|
||||
df["Klasse"] = "Alle"
|
||||
col_mapping = {}
|
||||
for col in df.columns:
|
||||
lower_col = col.lower()
|
||||
if lower_col in ["vorname kind", "vorname"]:
|
||||
col_mapping[col] = "Vorname"
|
||||
elif lower_col in ["nachname kind", "nachname"]:
|
||||
col_mapping[col] = "Nachname"
|
||||
elif lower_col in ["gruppe", "klasse"]:
|
||||
col_mapping[col] = "Klasse"
|
||||
df = df.rename(columns=col_mapping)
|
||||
df = df.fillna("")
|
||||
if "Vorname" not in df.columns: df["Vorname"] = ""
|
||||
if "Nachname" not in df.columns: df["Nachname"] = ""
|
||||
if "Klasse" not in df.columns: df["Klasse"] = "Alle"
|
||||
df = df.sort_values(by=["Klasse", "Nachname", "Vorname"])
|
||||
grouped = df.groupby("Klasse")
|
||||
class_data = []
|
||||
for class_name, group in grouped:
|
||||
|
||||
Reference in New Issue
Block a user