| | |
| | | from app.auth import get_current_user |
| | | from app.database import get_db |
| | | from app.grader_scope import assert_subject_allowed |
| | | from app.student_no import ensure_student_no, find_attempt_by_student_no |
| | | from app.system_settings import get_or_create_settings |
| | | from app.models import ( |
| | | ExamPaperMap, |
| | | ExaminationExamExaminee, |
| | |
| | | from app.schemas import AttemptDetail, PartGroup, QuestionDetail |
| | | |
| | | router = APIRouter(prefix="/api", tags=["attempts"]) |
| | | |
| | | |
| | | @router.get("/attempts/lookup/{student_no}") |
| | | def lookup_attempt( |
| | | student_no: str, |
| | | db: Session = Depends(get_db), |
| | | user: User = Depends(get_current_user), |
| | | ): |
| | | """根据编码反查答卷,返回 attempt_id 供前端跳转。""" |
| | | attempt = find_attempt_by_student_no(db, student_no) |
| | | if not attempt: |
| | | raise HTTPException(404, detail="编码不存在") |
| | | batch = db.get(ImportBatch, attempt.import_batch_id) |
| | | assert_subject_allowed(db, user, batch.subject_name if batch else None) |
| | | return {"attempt_id": str(attempt.id)} |
| | | |
| | | |
| | | @router.get("/attempts/{attempt_id}", response_model=AttemptDetail) |
| | |
| | | examinee = db.get(ExaminationExaminee, attempt.examinee_id) |
| | | batch = db.get(ImportBatch, attempt.import_batch_id) |
| | | assert_subject_allowed(db, user, batch.subject_name if batch else None) |
| | | |
| | | settings = get_or_create_settings(db) |
| | | hide_privacy = user.role == "grader" and not settings.grader_can_see_privacy |
| | | |
| | | pmap = db.scalar( |
| | | select(ExamPaperMap).where(ExamPaperMap.exam_id == attempt.exam_id) |
| | | ) |
| | |
| | | ) |
| | | ) |
| | | |
| | | student_no = ensure_student_no(db, attempt) |
| | | |
| | | return AttemptDetail( |
| | | attempt_id=str(attempt.id), |
| | | examinee_name=examinee.nickname if examinee else None, |
| | | id_card=examinee.id_card if examinee else None, |
| | | student_no=student_no, |
| | | examinee_name=None if hide_privacy else (examinee.nickname if examinee else None), |
| | | id_card=None if hide_privacy else (examinee.id_card if examinee else None), |
| | | score=attempt.score, |
| | | paper_total_score=paper.total_score if paper else None, |
| | | paper_name=paper.paper_name if paper else None, |