HH/apps/executive_summary/pdf_service.py
ismail c5f76b3855
Some checks are pending
Build and Push Docker Image / build (push) Waiting to run
updates
2026-05-11 14:45:30 +03:00

35 lines
947 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, user=None) -> bytes:
"""
Generate a PDF byte stream for an ExecutiveReport.
Args:
report: ExecutiveReport instance
user: User requesting the PDF (optional)
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"),
"user": user,
}
html_string = render_to_string("executive/pdf_report.html", context)
return HTML(string=html_string).write_pdf()