feat(list-generator): add logo to pdf header [32788f42]

This commit is contained in:
2026-03-20 12:43:33 +00:00
parent cef9d9ae11
commit 031a280a62
3 changed files with 38 additions and 3 deletions

View File

@@ -3,6 +3,16 @@ import os
from jinja2 import Environment, FileSystemLoader
from weasyprint import HTML
import datetime
import base64
def get_logo_base64():
logo_path = os.path.join(os.path.dirname(__file__), "..", "..", "assets", "logo.png")
try:
with open(logo_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode('utf-8')
except FileNotFoundError:
print(f"Warning: Logo file not found at {logo_path}")
return None
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 = None
@@ -43,7 +53,16 @@ def generate_school_pdf(institution: str, date_info: str, list_type: str, studen
env = Environment(loader=FileSystemLoader(template_dir))
template = env.get_template("school_list.html")
current_time = datetime.datetime.now().strftime("%d.%m.%Y %H:%M Uhr")
html_out = template.render(institution=institution, date_info=date_info, class_counts=class_counts, total_students=total_students, class_data=class_data, current_time=current_time)
logo_base64 = get_logo_base64()
html_out = template.render(
institution=institution,
date_info=date_info,
class_counts=class_counts,
total_students=total_students,
class_data=class_data,
current_time=current_time,
logo_base64=logo_base64
)
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"

View File

@@ -20,7 +20,15 @@
.footer-left { text-align: left; }
.footer-right { text-align: right; white-space: pre-wrap; }
</style></head><body>
<div class="header"><div class="institution-name">{{ institution }}</div><div class="date-info">{{ date_info }}</div></div>
<div class="header" style="display: flex; justify-content: space-between; align-items: center;">
<div>
<div class="institution-name">{{ institution }}</div>
<div class="date-info">{{ date_info }}</div>
</div>
<div>
<img src="data:image/png;base64,{{ logo_base64 }}" alt="Logo" style="max-height: 60px;">
</div>
</div>
<div class="summary"><h2>Übersicht der Anmeldungen:</h2><table class="summary-table">
{% for count in class_counts %}
<tr><td style="width: 50%;">Klasse {{ count.name }}</td><td>{{ count.count }} Anmeldungen</td></tr>
@@ -28,7 +36,15 @@
</table><div class="summary-total">Gesamt: {{ total_students }} Anmeldungen</div></div>
{% for class_info in class_data %}
<div class="class-section">
<div class="header"><div class="institution-name">{{ institution }}</div><div class="date-info">{{ date_info }}</div></div>
<div class="header" style="display: flex; justify-content: space-between; align-items: center;">
<div>
<div class="institution-name">{{ institution }}</div>
<div class="date-info">{{ date_info }}</div>
</div>
<div>
<img src="data:image/png;base64,{{ logo_base64 }}" alt="Logo" style="max-height: 60px;">
</div>
</div>
<table class="student-table"><thead><tr><th style="width: 40%">Nachname</th><th style="width: 40%">Vorname</th><th style="width: 20%">Klasse</th></tr></thead><tbody>
{% for student in class_info.students %}
<tr><td>{{ student.Nachname }}</td><td>{{ student.Vorname }}</td><td>{{ student.Klasse }}</td></tr>

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB