Additional bugfixes
This commit is contained in:
@@ -14,7 +14,7 @@ from sqlalchemy.orm import sessionmaker, Session
|
||||
from app.core.audit import ExportRecord, append_audit, current_span_context
|
||||
from app.core.config import settings
|
||||
from app.core.executor import get_executor
|
||||
from app.core.export import to_pdf_bytes
|
||||
from app.core.export import to_pdf_bytes, to_xlsx_bytes
|
||||
from app.core.security import FrontendPrincipal, require_frontend_principal
|
||||
from app.domain.wwi import analytics
|
||||
|
||||
@@ -379,6 +379,24 @@ async def export_wwi_business_events(
|
||||
data = await asyncio.get_running_loop().run_in_executor(
|
||||
get_executor(), lambda: analytics.get_business_events(pg_factory, limit=limit)
|
||||
)
|
||||
|
||||
if format == "xlsx":
|
||||
today = datetime.now(timezone.utc).strftime("%Y%m%d")
|
||||
filename = f"wwi_business_events_{today}.xlsx"
|
||||
trace_id, span_id = current_span_context()
|
||||
|
||||
def _build_xlsx():
|
||||
content = to_xlsx_bytes(data)
|
||||
_record_export(pg_factory, "wwi", "business-events", "xlsx", filters,
|
||||
len(data), len(content), actor_id, trace_id, span_id)
|
||||
return content
|
||||
|
||||
content = await asyncio.get_running_loop().run_in_executor(get_executor(), _build_xlsx)
|
||||
return Response(
|
||||
content=content, media_type=_XLSX_MEDIA,
|
||||
headers={"Content-Disposition": f'attachment; filename="{filename}"'},
|
||||
)
|
||||
|
||||
return await asyncio.get_running_loop().run_in_executor(
|
||||
get_executor(),
|
||||
lambda: _make_pdf(data, "wwi_business_events",
|
||||
|
||||
Reference in New Issue
Block a user