fix(report_engine): lazy-init output dir to fix CI PermissionError on /app
Aegis CI / lint-and-test (push) Has been cancelled
Snyk Security Scan / Python vulnerabilities (backend) (push) Has been cancelled
Snyk Security Scan / npm vulnerabilities (frontend) (push) Has been cancelled
Snyk Security Scan / Docker image vulnerabilities (backend) (push) Has been cancelled

This commit is contained in:
kitos
2026-06-12 14:13:41 +02:00
parent 88c2af472e
commit 443a04befb
+6 -2
View File
@@ -31,7 +31,7 @@ class ReportEngine:
# Define function __init__ # Define function __init__
def __init__(self) -> None: def __init__(self) -> None:
"""Initialise the Jinja2 environment and ensure the output directory exists.""" """Initialise the Jinja2 environment."""
# Assign self.jinja_env = Environment( # Assign self.jinja_env = Environment(
self.jinja_env = Environment( self.jinja_env = Environment(
# Keyword argument: loader # Keyword argument: loader
@@ -39,7 +39,8 @@ class ReportEngine:
# Keyword argument: autoescape # Keyword argument: autoescape
autoescape=True, autoescape=True,
) )
# Call os.makedirs()
def _ensure_output_dir(self) -> None:
os.makedirs(settings.REPORT_OUTPUT_DIR, exist_ok=True) os.makedirs(settings.REPORT_OUTPUT_DIR, exist_ok=True)
# Define function render_html # Define function render_html
@@ -57,6 +58,7 @@ class ReportEngine:
# Define function generate_pdf # Define function generate_pdf
def generate_pdf(self, template_name: str, context: dict) -> str: def generate_pdf(self, template_name: str, context: dict) -> str:
"""Render HTML and convert to PDF with WeasyPrint.""" """Render HTML and convert to PDF with WeasyPrint."""
self._ensure_output_dir()
# Import CSS, HTML from weasyprint # Import CSS, HTML from weasyprint
from weasyprint import CSS, HTML from weasyprint import CSS, HTML
@@ -93,6 +95,7 @@ class ReportEngine:
# Define function generate_docx # Define function generate_docx
def generate_docx(self, template_name: str, context: dict) -> str: def generate_docx(self, template_name: str, context: dict) -> str:
"""Render a .docx template with docxtpl.""" """Render a .docx template with docxtpl."""
self._ensure_output_dir()
# Import DocxTemplate from docxtpl # Import DocxTemplate from docxtpl
from docxtpl import DocxTemplate from docxtpl import DocxTemplate
@@ -131,6 +134,7 @@ class ReportEngine:
# Define function generate_html_file # Define function generate_html_file
def generate_html_file(self, template_name: str, context: dict) -> str: def generate_html_file(self, template_name: str, context: dict) -> str:
"""Render and save a standalone HTML report.""" """Render and save a standalone HTML report."""
self._ensure_output_dir()
# Assign html_content = self.render_html(template_name, context) # Assign html_content = self.render_html(template_name, context)
html_content = self.render_html(template_name, context) html_content = self.render_html(template_name, context)
# Assign output_path = os.path.join( # Assign output_path = os.path.join(