2023-01-14 17:38:03 +01:00
|
|
|
from flask import abort
|
|
|
|
|
2023-01-16 01:12:15 +01:00
|
|
|
from ...coordinator.utils import attach_points_for_first_and_second_term_to_group
|
2023-01-14 17:38:03 +01:00
|
|
|
from ...dependencies import db
|
|
|
|
from ...students.models import Group, ProjectGradeSheet
|
|
|
|
from ..models import ProjectSupervisor
|
|
|
|
|
|
|
|
|
2023-01-16 01:12:15 +01:00
|
|
|
def update_project_grade_sheet(
|
|
|
|
group_id: int, query: dict, data: dict
|
|
|
|
) -> ProjectGradeSheet:
|
2023-01-14 17:38:03 +01:00
|
|
|
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)
|
2023-01-16 01:12:15 +01:00
|
|
|
attach_points_for_first_and_second_term_to_group(group)
|
2023-01-14 17:38:03 +01:00
|
|
|
db.session.commit()
|