39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
from apiflask import APIBlueprint
|
|
from flask import abort
|
|
|
|
from ..models import ProjectGradeSheet, Student
|
|
from ..schemas import (
|
|
ProjectGradeSheetDetailFirstTermSchema,
|
|
ProjectGradeSheetDetailSecondTermSchema,
|
|
StudentIndexQueryTempSchema,
|
|
)
|
|
|
|
bp = APIBlueprint("project_grade_sheet", __name__, url_prefix="/project-grade-sheet")
|
|
|
|
|
|
@bp.get("/year-group/<int:year_group_id>/")
|
|
@bp.input(StudentIndexQueryTempSchema, location="query")
|
|
def detail_project_grade_sheet(year_group_id: int, query: dict) -> dict:
|
|
student_id = query.get("student_id")
|
|
st = Student.query.filter(Student.id == student_id).first()
|
|
if st is None:
|
|
abort(404, "Not found student!")
|
|
####################################
|
|
term = int(query.get("term"))
|
|
|
|
groups = [g for g in st.groups if g.year_group_id == year_group_id]
|
|
if len(groups) == 0:
|
|
abort(404, "Not found group!")
|
|
group = groups[0]
|
|
|
|
pgs = ProjectGradeSheet.query.filter(ProjectGradeSheet.group_id == group.id).first()
|
|
if pgs is None:
|
|
abort(404, "Not found project grade sheet!")
|
|
|
|
if term == 1:
|
|
schema = ProjectGradeSheetDetailFirstTermSchema()
|
|
else:
|
|
schema = ProjectGradeSheetDetailSecondTermSchema()
|
|
|
|
return schema.dump(pgs)
|