2022-12-15 20:44:03 +01:00
|
|
|
from apiflask import APIBlueprint
|
|
|
|
from flask import abort
|
|
|
|
|
2023-01-14 17:38:03 +01:00
|
|
|
from ..models import ProjectGradeSheet, Student
|
|
|
|
from ..schemas import (
|
|
|
|
ProjectGradeSheetDetailFirstTermSchema,
|
|
|
|
ProjectGradeSheetDetailSecondTermSchema,
|
|
|
|
StudentIndexQueryTempSchema,
|
|
|
|
)
|
2022-12-15 20:44:03 +01:00
|
|
|
|
|
|
|
bp = APIBlueprint("project_grade_sheet", __name__, url_prefix="/project-grade-sheet")
|
|
|
|
|
|
|
|
|
2023-01-14 17:38:03 +01:00
|
|
|
@bp.get("/year-group/<int:year_group_id>/")
|
|
|
|
@bp.input(StudentIndexQueryTempSchema, location="query")
|
2022-12-15 20:44:03 +01:00
|
|
|
def detail_project_grade_sheet(year_group_id: int, query: dict) -> dict:
|
2023-01-14 17:38:03 +01:00
|
|
|
student_id = query.get("student_id")
|
|
|
|
st = Student.query.filter(Student.id == student_id).first()
|
2022-12-15 20:44:03 +01:00
|
|
|
if st is None:
|
|
|
|
abort(404, "Not found student!")
|
|
|
|
####################################
|
2023-01-14 17:38:03 +01:00
|
|
|
term = int(query.get("term"))
|
2022-12-15 20:44:03 +01:00
|
|
|
|
|
|
|
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)
|