feat(list-generator): add logo to pdf header [32788f42]
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user