36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
"""
|
|
Rutas para descargar plantillas CSV generadas desde código (sin archivos XLS/XLSX).
|
|
"""
|
|
from typing import Any, Dict
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
from fastapi.responses import Response
|
|
|
|
from core.security import get_current_user
|
|
|
|
from .registry import generate_csv_content, get_template_filename
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/{template_id}", response_class=Response)
|
|
async def download_csv_template(
|
|
template_id: str,
|
|
current_user: Dict[str, Any] = Depends(get_current_user),
|
|
):
|
|
"""
|
|
Devuelve un CSV con solo la fila de cabeceras para la plantilla indicada.
|
|
Las cabeceras son los nombres canónicos definidos en cada template_config.
|
|
"""
|
|
content = generate_csv_content(template_id, include_bom=True)
|
|
if content is None:
|
|
raise HTTPException(status_code=404, detail=f"Plantilla desconocida: {template_id}")
|
|
filename = get_template_filename(template_id)
|
|
return Response(
|
|
content=content,
|
|
media_type="text/csv; charset=utf-8",
|
|
headers={
|
|
"Content-Disposition": f'attachment; filename="{filename}"',
|
|
},
|
|
)
|