Add PDF download button to dashboard
This commit is contained in:
@@ -876,6 +876,51 @@ def results_viewer_page() -> None:
|
|||||||
if selected_run.description:
|
if selected_run.description:
|
||||||
st.markdown(f"**Description:** {selected_run.description}")
|
st.markdown(f"**Description:** {selected_run.description}")
|
||||||
|
|
||||||
|
# PDF Report Generation
|
||||||
|
st.markdown("### Export Report")
|
||||||
|
col_btn, col_status = st.columns([1, 3])
|
||||||
|
|
||||||
|
with col_btn:
|
||||||
|
generate_pdf = st.button("Generate PDF Report", type="primary")
|
||||||
|
|
||||||
|
if generate_pdf:
|
||||||
|
try:
|
||||||
|
from py_dvt_ate.reporting import ReportConfig, ReportGenerator
|
||||||
|
|
||||||
|
report_config = ReportConfig(
|
||||||
|
company_name="py_dvt_ate",
|
||||||
|
include_charts=True,
|
||||||
|
chart_dpi=150,
|
||||||
|
)
|
||||||
|
generator = ReportGenerator(
|
||||||
|
repository=repository,
|
||||||
|
config=report_config,
|
||||||
|
)
|
||||||
|
|
||||||
|
with st.spinner("Generating PDF report..."):
|
||||||
|
pdf_bytes = generator.generate_bytes(UUID(selected_run.id))
|
||||||
|
|
||||||
|
st.session_state.pdf_bytes = pdf_bytes
|
||||||
|
st.session_state.pdf_filename = f"{selected_run.test_name}_{selected_run.id[:8]}.pdf"
|
||||||
|
st.success("PDF generated successfully!")
|
||||||
|
|
||||||
|
except ImportError:
|
||||||
|
st.error(
|
||||||
|
"PDF generation requires additional dependencies. "
|
||||||
|
"Install with: `pip install py_dvt_ate[reports]`"
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
st.error(f"Failed to generate PDF: {e}")
|
||||||
|
|
||||||
|
# Show download button if PDF was generated
|
||||||
|
if "pdf_bytes" in st.session_state and st.session_state.pdf_bytes:
|
||||||
|
st.download_button(
|
||||||
|
label="Download PDF",
|
||||||
|
data=st.session_state.pdf_bytes,
|
||||||
|
file_name=st.session_state.get("pdf_filename", "report.pdf"),
|
||||||
|
mime="application/pdf",
|
||||||
|
)
|
||||||
|
|
||||||
if selected_run.config_json:
|
if selected_run.config_json:
|
||||||
import json
|
import json
|
||||||
with st.expander("Test Configuration"):
|
with st.expander("Test Configuration"):
|
||||||
|
|||||||
Reference in New Issue
Block a user