Merge branch 'master' of https://git.wmi.amu.edu.pl/s459309/system-pri
This commit is contained in:
commit
56853fb906
@ -38,23 +38,18 @@ def create_group(data: dict) -> dict:
|
||||
students_indexes = data['students']
|
||||
project_supervisor_id = data['project_supervisor_id']
|
||||
|
||||
# can assign a new group to project_supervisor
|
||||
|
||||
# nie działa to poprawnie
|
||||
# result = db.session.query(ProjectSupervisor.count_groups - db.func.count(ProjectSupervisor.id)). \
|
||||
# join(Group).filter(ProjectSupervisor.id == project_supervisor_id). \
|
||||
# group_by(ProjectSupervisor.id).scalar()
|
||||
|
||||
# if result is None:
|
||||
# abort(400, "Project Supervisor doesnt exist")
|
||||
# elif result <= 0:
|
||||
# abort(400, "Can't create new group, project supervisor achieved a limit of groups")
|
||||
|
||||
project_supervisor = ProjectSupervisor.query.filter_by(id=project_supervisor_id).first()
|
||||
|
||||
if project_supervisor is None:
|
||||
abort(400, "Project Supervisor with id {project_supervisor_id} doesnt exist")
|
||||
elif project_supervisor.limit_group == project_supervisor.count_groups:
|
||||
abort(400, f"Project Supervisor with id {project_supervisor_id} doesnt exist")
|
||||
elif project_supervisor.limit_group < len(students_indexes):
|
||||
abort(400, f"Too much students you want add to group, "
|
||||
f"this group can have only {project_supervisor.limit_group} students")
|
||||
|
||||
result = db.session.query(ProjectSupervisor.count_groups - db.func.count(ProjectSupervisor.id)).join(Group).filter(
|
||||
ProjectSupervisor.id == project_supervisor_id).group_by(ProjectSupervisor.id).scalar()
|
||||
|
||||
if result is not None and result <= 0:
|
||||
abort(400, "Can't create new group, project supervisor achieved a limit of groups")
|
||||
|
||||
group = Group(name=name, project_supervisor_id=project_supervisor_id)
|
||||
|
Loading…
Reference in New Issue
Block a user