2023-01-06 22:35:47 +01:00
|
|
|
from typing import List
|
|
|
|
|
2023-01-14 17:38:03 +01:00
|
|
|
from app.base.mode import ModeGroups
|
2023-01-09 22:32:58 +01:00
|
|
|
from app.dependencies import db
|
2023-01-10 00:17:25 +01:00
|
|
|
from app.examination_schedule.models import ExaminationSchedule
|
2023-01-14 17:38:03 +01:00
|
|
|
from app.project_supervisor.models import ProjectSupervisor, YearGroup
|
|
|
|
from app.students.models import Group, Student, YearGroupStudents
|
|
|
|
|
|
|
|
from .factory import (
|
|
|
|
ExaminationScheduleFactory,
|
|
|
|
GroupFactory,
|
|
|
|
ProjectSupervisorFactory,
|
|
|
|
StudentFactory,
|
|
|
|
YearGroupProjectSupervisorsFactory,
|
|
|
|
YearGroupStudentsFactory,
|
|
|
|
)
|
2023-01-06 22:35:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
def create_year_group(data: dict = None) -> YearGroup:
|
|
|
|
if data is None:
|
2023-01-14 17:38:03 +01:00
|
|
|
data = {"mode": ModeGroups.STATIONARY.value, "name": "2022/2023"}
|
2023-01-06 22:35:47 +01:00
|
|
|
yg = YearGroup(**data)
|
|
|
|
db.session.add(yg)
|
|
|
|
db.session.commit()
|
|
|
|
return yg
|
|
|
|
|
|
|
|
|
2023-01-14 17:38:03 +01:00
|
|
|
def create_project_supervisors(
|
|
|
|
yg: YearGroup, amount: int, limit_group: int = 3
|
|
|
|
) -> List[ProjectSupervisorFactory]:
|
2023-01-06 22:35:47 +01:00
|
|
|
ps = [ProjectSupervisorFactory() for _ in range(amount)]
|
|
|
|
db.session.add_all(ps)
|
|
|
|
db.session.commit()
|
|
|
|
db.session.add_all(
|
2023-01-14 17:38:03 +01:00
|
|
|
[
|
|
|
|
YearGroupProjectSupervisorsFactory(
|
|
|
|
limit_group=limit_group, year_group_id=yg.id, project_supervisor_id=p.id
|
|
|
|
)
|
|
|
|
for p in ps
|
|
|
|
]
|
|
|
|
)
|
2023-01-06 22:35:47 +01:00
|
|
|
db.session.commit()
|
|
|
|
return ps
|
2023-01-08 17:15:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
def create_dummy_ps(data: dict) -> ProjectSupervisor:
|
|
|
|
ps = ProjectSupervisor(**data)
|
|
|
|
db.session.add(ps)
|
|
|
|
db.session.commit()
|
|
|
|
return ps
|
|
|
|
|
|
|
|
|
|
|
|
def create_dummy_group(data: dict, project_supervisor_id: int) -> Group:
|
|
|
|
group = Group(**data, project_supervisor_id=project_supervisor_id)
|
|
|
|
db.session.add(group)
|
|
|
|
db.session.commit()
|
|
|
|
return group
|
|
|
|
|
|
|
|
|
|
|
|
def create_students(yg: YearGroup, amount: int) -> List[StudentFactory]:
|
|
|
|
students = [StudentFactory() for _ in range(amount)]
|
|
|
|
db.session.add_all(students)
|
|
|
|
db.session.commit()
|
2023-01-14 17:38:03 +01:00
|
|
|
db.session.add_all(
|
|
|
|
[
|
|
|
|
YearGroupStudentsFactory(year_group_id=yg.id, student_index=s.index)
|
|
|
|
for s in students
|
|
|
|
]
|
|
|
|
)
|
2023-01-08 17:15:02 +01:00
|
|
|
db.session.commit()
|
|
|
|
return students
|
|
|
|
|
|
|
|
|
2023-01-09 22:32:58 +01:00
|
|
|
def create_student(data: dict, year_group_id: int = None) -> Student:
|
2023-01-08 17:15:02 +01:00
|
|
|
st = Student(**data)
|
|
|
|
db.session.add(st)
|
|
|
|
db.session.commit()
|
2023-01-09 22:32:58 +01:00
|
|
|
if year_group_id is not None:
|
2023-01-14 17:38:03 +01:00
|
|
|
db.session.add(
|
|
|
|
YearGroupStudents(year_group_id=year_group_id, student_index=st.index)
|
|
|
|
)
|
2023-01-09 22:32:58 +01:00
|
|
|
db.session.commit()
|
2023-01-08 17:15:02 +01:00
|
|
|
return st
|
2023-01-08 20:26:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
def create_groups(yg: YearGroup, amount: int) -> List[Group]:
|
|
|
|
groups = [GroupFactory(year_group_id=yg.id) for _ in range(amount)]
|
|
|
|
db.session.add_all(groups)
|
|
|
|
db.session.commit()
|
|
|
|
return groups
|
|
|
|
|
|
|
|
|
|
|
|
def create_group(data: dict, yg: YearGroup) -> Group:
|
|
|
|
group = Group(**data, year_group_id=yg.id)
|
|
|
|
db.session.add(group)
|
|
|
|
db.session.commit()
|
|
|
|
return group
|
2023-01-10 00:17:25 +01:00
|
|
|
|
|
|
|
|
2023-01-14 17:38:03 +01:00
|
|
|
def create_examination_schedules(
|
|
|
|
yg: YearGroup, amount: int
|
|
|
|
) -> List[ExaminationScheduleFactory]:
|
|
|
|
examination_schedules = [
|
|
|
|
ExaminationScheduleFactory(year_group_id=yg.id) for _ in range(amount)
|
|
|
|
]
|
2023-01-10 00:17:25 +01:00
|
|
|
db.session.add_all(examination_schedules)
|
|
|
|
db.session.commit()
|
|
|
|
return examination_schedules
|
|
|
|
|
|
|
|
|
|
|
|
def create_examination_schedule(data: dict, yg: YearGroup) -> ExaminationSchedule:
|
|
|
|
ex = ExaminationSchedule(**data, year_group_id=yg.id)
|
|
|
|
db.session.add(ex)
|
|
|
|
db.session.commit()
|
|
|
|
return ex
|