36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
from flask import abort
|
|
|
|
from ...coordinator.utils import attach_points_for_first_and_second_term_to_group
|
|
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
|
|
) -> ProjectGradeSheet:
|
|
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)
|
|
attach_points_for_first_and_second_term_to_group(group)
|
|
db.session.commit()
|