forked from ChelseaKR/ceqa-preflight
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreporting.py
More file actions
42 lines (26 loc) · 1.49 KB
/
Copy pathreporting.py
File metadata and controls
42 lines (26 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Small, accessible-by-default text and JSON report renderers."""
from __future__ import annotations
import json
from jinja2 import Environment, PackageLoader, select_autoescape
from ceqa_preflight.models import Finding, InspectionReport
_TEMPLATES = Environment(
loader=PackageLoader("ceqa_preflight", "templates"),
autoescape=select_autoescape(enabled_extensions=("html", "j2"), default_for_string=True),
)
def render_json(report: InspectionReport) -> str:
"""Return stable, indented JSON for a report without writing to disk."""
return json.dumps(report.model_dump(mode="json"), indent=2, sort_keys=True) + "\n"
def _render_finding(finding: Finding) -> str:
location = f" ({finding.document})" if finding.document else ""
return f"[{finding.status.value.upper()}] {finding.rule_id}{location}: {finding.message}"
def render_console(report: InspectionReport) -> str:
"""Return plain text that remains useful with a terminal screen reader."""
lines = ["CEQA Preflight advisory report", report.disclaimer, ""]
lines.extend(_render_finding(finding) for finding in report.findings)
if report.manual_review:
lines.extend(["", "Manual review"])
lines.extend(_render_finding(finding) for finding in report.manual_review)
return "\n".join(lines) + "\n"
def render_html(report: InspectionReport) -> str:
"""Render a self-contained, semantic HTML report without JavaScript."""
return _TEMPLATES.get_template("report.html.j2").render(report=report)