system-pri/backend/app/project_supervisor/query/project_grade_sheet.py

32 lines
1.0 KiB
Python
Raw Normal View History

from flask import abort
from ...dependencies import db
from ...students.models import Group, ProjectGradeSheet
from ..models import ProjectSupervisor
def update_project_grade_sheet(group_id: int, query: dict, data: dict) -> None:
project_supervisor_id = query.get("id")
project_supervisor = ProjectSupervisor.query.filter(
ProjectSupervisor.id == project_supervisor_id
).first()
if project_supervisor is None:
abort(404, "ProjectSupervisor doesn't exist!")
####################################
if len(data) == 0:
abort(400, "You passed empty data!")
group = Group.query.filter(
Group.project_supervisor_id == project_supervisor_id, Group.id == group_id
).first()
if group is None:
abort(400, "You cannot update project grade sheet! It's not your group!")
pgs_query = ProjectGradeSheet.query.filter(ProjectGradeSheet.group_id == group_id)
if pgs_query.first() is None:
abort(404, "Not found project grade sheet!")
pgs_query.update(data)
db.session.commit()