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
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:
@@ -31,7 +31,7 @@ class ReportEngine:
|
||||
|
||||
# Define function __init__
|
||||
def __init__(self) -> None:
|
||||
"""Initialise the Jinja2 environment and ensure the output directory exists."""
|
||||
"""Initialise the Jinja2 environment."""
|
||||
# Assign self.jinja_env = Environment(
|
||||
self.jinja_env = Environment(
|
||||
# Keyword argument: loader
|
||||
@@ -39,7 +39,8 @@ class ReportEngine:
|
||||
# Keyword argument: autoescape
|
||||
autoescape=True,
|
||||
)
|
||||
# Call os.makedirs()
|
||||
|
||||
def _ensure_output_dir(self) -> None:
|
||||
os.makedirs(settings.REPORT_OUTPUT_DIR, exist_ok=True)
|
||||
|
||||
# Define function render_html
|
||||
@@ -57,6 +58,7 @@ class ReportEngine:
|
||||
# Define function generate_pdf
|
||||
def generate_pdf(self, template_name: str, context: dict) -> str:
|
||||
"""Render HTML and convert to PDF with WeasyPrint."""
|
||||
self._ensure_output_dir()
|
||||
# Import CSS, HTML from weasyprint
|
||||
from weasyprint import CSS, HTML
|
||||
|
||||
@@ -93,6 +95,7 @@ class ReportEngine:
|
||||
# Define function generate_docx
|
||||
def generate_docx(self, template_name: str, context: dict) -> str:
|
||||
"""Render a .docx template with docxtpl."""
|
||||
self._ensure_output_dir()
|
||||
# Import DocxTemplate from docxtpl
|
||||
from docxtpl import DocxTemplate
|
||||
|
||||
@@ -131,6 +134,7 @@ class ReportEngine:
|
||||
# Define function generate_html_file
|
||||
def generate_html_file(self, template_name: str, context: dict) -> str:
|
||||
"""Render and save a standalone HTML report."""
|
||||
self._ensure_output_dir()
|
||||
# Assign html_content = self.render_html(template_name, context)
|
||||
html_content = self.render_html(template_name, context)
|
||||
# Assign output_path = os.path.join(
|
||||
|
||||
Reference in New Issue
Block a user