from apiflask import APIBlueprint from flask import abort from ..schemas import StudentIndexQueryTempSchema, ProjectGradeSheetDetailFirstTermSchema, \ ProjectGradeSheetDetailSecondTermSchema from ..models import Student, ProjectGradeSheet bp = APIBlueprint("project_grade_sheet", __name__, url_prefix="/project-grade-sheet") @bp.get('/year-group//') @bp.input(StudentIndexQueryTempSchema, location='query') def detail_project_grade_sheet(year_group_id: int, query: dict) -> dict: index = query.get('index') st = Student.query.filter(Student.index == index).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)