[32788f42] fix(list-generator): fix syntax error in f-string and fix truncation in pdf_generator.py
This commit is contained in:
@@ -5,28 +5,20 @@ 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:
|
||||
# Read CSV data
|
||||
df = pd.read_csv(students_csv_path, sep=";")
|
||||
# Clean column names
|
||||
df.columns = df.columns.str.strip()
|
||||
|
||||
# Group by class
|
||||
if "Klasse" not in df.columns:
|
||||
df["Klasse"] = "Alle"
|
||||
grouped = df.groupby("Klasse")
|
||||
class_data = []
|
||||
for class_name, group in grouped:
|
||||
students = group.to_dict("records")
|
||||
class_data.append({"name": class_name, "students": students})
|
||||
|
||||
# Prepare summary data
|
||||
class_counts = [{"name": c, "count": len(g)} for c, g in grouped]
|
||||
total_students = sum(c["count"] for c in class_counts)
|
||||
|
||||
# Setup Jinja2 environment
|
||||
template_dir = os.path.join(os.path.dirname(__file__), "..", "templates")
|
||||
env = Environment(loader=FileSystemLoader(template_dir))
|
||||
template = env.get_template("school_list.html")
|
||||
|
||||
# Render HTML
|
||||
current_time = datetime.datetime.now().strftime("%d.%m.%Y %H:%M Uhr")
|
||||
html_out = template.render(
|
||||
institution=institution,
|
||||
@@ -36,10 +28,9 @@ def generate_school_pdf(institution: str, date_info: str, list_type: str, studen
|
||||
class_data=class_data,
|
||||
current_time=current_time
|
||||
)
|
||||
|
||||
# Generate PDF
|
||||
output_filename = f"Listen_{institution.replace( , _)}_{list_type}_{datetime.datetime.now().strftime(%Y-%m-%d_%H-%M)}.pdf"
|
||||
clean_inst = institution.replace(" ", "_").replace("/", "-")
|
||||
time_str = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M")
|
||||
output_filename = f"Listen_{clean_inst}_{list_type}_{time_str}.pdf"
|
||||
output_path = os.path.join(output_dir, output_filename)
|
||||
HTML(string=html_out).write_pdf(output_path)
|
||||
|
||||
return output_path
|
||||
|
||||
Reference in New Issue
Block a user