template.py 778 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import os
  4. from fastapi import APIRouter, Query, Depends
  5. from fastapi.responses import FileResponse
  6. from models.user import SysUser
  7. from utils.depends import get_current_user
  8. from core.config import settings
  9. router = APIRouter()
  10. @router.get("/templates", summary="模板下载")
  11. async def download(tmpl: str = Query(...,
  12. description="模板类型,取值:teacher / student"),
  13. current_user: SysUser = Depends(get_current_user)):
  14. filename = f"tmpl_{tmpl}.xlsx"
  15. tmpl_path = os.path.join(settings.TEMPLATE_PATH, filename)
  16. if not os.path.exists:
  17. return {"errcode": 400, "mess": "模板不存在!"}
  18. return FileResponse(tmpl_path, filename=filename)