feat: add KS-3 Excel/Word export

This commit is contained in:
Арсентьев Александр
2026-09-27 14:36:42 +03:00
parent 34fb98e69c
commit 6e365ac434
8 changed files with 699 additions and 6 deletions
+34 -2
View File
@@ -3,7 +3,7 @@ from decimal import Decimal
from pathlib import Path
from fastapi import APIRouter, Depends, Form, HTTPException, Request
from fastapi.responses import RedirectResponse
from fastapi.responses import RedirectResponse, Response
from fastapi.templating import Jinja2Templates
from sqlalchemy.orm import Session, joinedload
@@ -164,4 +164,36 @@ async def ks3_cancel(project_id: int, ks3_id: int, db: Session = Depends(get_db)
raise HTTPException(status_code=400, detail="KS-3 already cancelled")
doc.status = "cancelled"
db.commit()
return RedirectResponse(f"/projects/{project_id}/ks3/{ks3_id}", status_code=303)
return RedirectResponse(f"/projects/{project_id}/ks3/{ks3_id}", status_code=303)
@router.get("/{project_id}/ks3/{ks3_id}/export/excel")
async def ks3_export_excel(project_id: int, ks3_id: int, db: Session = Depends(get_db)):
document = _document(db, project_id, ks3_id)
from app.exporters import safe_export_filename, content_disposition
from app.exporters.ks3_dto import build_ks3_export_dto
from app.exporters.excel.ks3_renderer import render_ks3_excel
dto = build_ks3_export_dto(db, document)
data = render_ks3_excel(dto)
filename = safe_export_filename("КС-3", document.number, document.date, "xlsx")
return Response(
content=data,
media_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
headers={"Content-Disposition": content_disposition(filename)},
)
@router.get("/{project_id}/ks3/{ks3_id}/export/word")
async def ks3_export_word(project_id: int, ks3_id: int, db: Session = Depends(get_db)):
document = _document(db, project_id, ks3_id)
from app.exporters import safe_export_filename, content_disposition
from app.exporters.ks3_dto import build_ks3_export_dto
from app.exporters.word.ks3_renderer import render_ks3_word
dto = build_ks3_export_dto(db, document)
data = render_ks3_word(dto)
filename = safe_export_filename("КС-3", document.number, document.date, "docx")
return Response(
content=data,
media_type="application/vnd.openxmlformats-officedocument.wordprocessingml.document",
headers={"Content-Disposition": content_disposition(filename)},
)