33 lines
865 B
Python
33 lines
865 B
Python
"""
|
|
PDF generation service for executive reports.
|
|
|
|
Renders the executive PDF template without requiring an HttpRequest.
|
|
"""
|
|
|
|
from django.template.loader import render_to_string
|
|
from django.utils import timezone
|
|
from weasyprint import HTML
|
|
|
|
|
|
def generate_executive_pdf(report) -> bytes:
|
|
"""
|
|
Generate a PDF byte stream for an ExecutiveReport.
|
|
|
|
Args:
|
|
report: ExecutiveReport instance
|
|
|
|
Returns:
|
|
PDF file contents as bytes
|
|
"""
|
|
context = {
|
|
"report": report,
|
|
"narrative": report.narrative_en,
|
|
"highlights": report.highlights_en,
|
|
"concerns": report.concerns_en,
|
|
"metrics": report.metrics_snapshot,
|
|
"generated_at": timezone.now().strftime("%Y-%m-%d %H:%M"),
|
|
}
|
|
|
|
html_string = render_to_string("executive/pdf_report.html", context)
|
|
return HTML(string=html_string).write_pdf()
|