20160116
This commit is contained in:
@@ -14,14 +14,26 @@ def export_report(format: str = "xlsx", db: Session = Depends(get_db)):
|
||||
|
||||
generator = ReportGenerator(db)
|
||||
|
||||
print(f"Export request received. Format: {format}")
|
||||
|
||||
if format == 'xlsx':
|
||||
output = generator.generate_excel()
|
||||
media_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||
filename = "dit_attribution_report.xlsx"
|
||||
try:
|
||||
print("Generating Excel...")
|
||||
output = generator.generate_excel()
|
||||
print("Excel generated successfully.")
|
||||
media_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||
filename = "dit_attribution_report.xlsx"
|
||||
except Exception as e:
|
||||
print(f"Error generating Excel: {str(e)}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
else:
|
||||
output = generator.generate_pdf()
|
||||
media_type = "application/pdf"
|
||||
filename = "dit_attribution_report.pdf"
|
||||
try:
|
||||
output = generator.generate_pdf()
|
||||
media_type = "application/pdf"
|
||||
filename = "dit_attribution_report.pdf"
|
||||
except Exception as e:
|
||||
print(f"Error generating PDF: {str(e)}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
return StreamingResponse(
|
||||
output,
|
||||
|
||||
Reference in New Issue
Block a user