feat: 完善代码,应该可以进行签到了,就差测试了
This commit is contained in:
@@ -1,6 +1,19 @@
|
||||
from datetime import datetime
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
||||
from fastapi.responses import HTMLResponse
|
||||
import json
|
||||
import os
|
||||
from typing import List
|
||||
from uuid import uuid4
|
||||
from fastapi import (
|
||||
APIRouter,
|
||||
Depends,
|
||||
File,
|
||||
Form,
|
||||
HTTPException,
|
||||
Request,
|
||||
UploadFile,
|
||||
status,
|
||||
)
|
||||
from fastapi.responses import HTMLResponse, RedirectResponse
|
||||
from starlette.templating import Jinja2Templates
|
||||
from services.services import XBXS
|
||||
|
||||
@@ -88,7 +101,6 @@ async def sign_detail(
|
||||
know_detail = await xbxs.get_know(str(knowing_id))
|
||||
|
||||
data = know_detail.get("data", {})
|
||||
|
||||
# 获取具体的数据
|
||||
knowing_name = data.get("knowingName", "未知签到")
|
||||
start_date = data.get("startDate", "未知")
|
||||
@@ -98,12 +110,14 @@ async def sign_detail(
|
||||
send_role = data.get("sendRole", "未知")
|
||||
is_check = data.get("isCheck", 0)
|
||||
is_picture = data.get("isPicture", 0)
|
||||
is_finish_know = data.get("isFinishKnowing", 0)
|
||||
# is_finish_know = data.get("isFinishKnowing", 0)
|
||||
locations = json.loads(data.get("location", []))
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"sign_detail.html",
|
||||
{
|
||||
"request": request,
|
||||
"know_id": knowing_id,
|
||||
"knowing_name": knowing_name,
|
||||
"start_date": start_date,
|
||||
"start_time": start_time,
|
||||
@@ -112,6 +126,33 @@ async def sign_detail(
|
||||
"send_role": send_role,
|
||||
"is_check": is_check,
|
||||
"is_picture": is_picture,
|
||||
"is_finish_know": is_finish_know,
|
||||
"locations": locations,
|
||||
# "is_finish_know": is_finish_know,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
# 完善的 sign 完成接口
|
||||
@router.post("/sign/{know_id}/complete")
|
||||
async def complete_sign(
|
||||
know_id: int,
|
||||
request: Request,
|
||||
location: str = Form(...), # 获取经纬度,必填
|
||||
address: str = Form(...), # 获取经纬度,必填
|
||||
remark: str = Form(...), # 获取备注,必填
|
||||
images: List[UploadFile] = File(...), # 获取上传的图片,支持多张
|
||||
xbxs: XBXS = Depends(get_xbxs),
|
||||
):
|
||||
# 备注必填,未填写时返回错误
|
||||
if not remark:
|
||||
raise HTTPException(status_code=400, detail="备注是必填项")
|
||||
|
||||
print(location, remark, know_id, images, address)
|
||||
|
||||
try:
|
||||
await xbxs.update_student_know(str(know_id), remark, address, location, images)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail="保存签到数据失败")
|
||||
|
||||
# 成功后跳转到签到列表
|
||||
return RedirectResponse(url="/sign", status_code=status.HTTP_303_SEE_OTHER)
|
||||
|
||||
Reference in New Issue
Block a user