2023-01-06 22:35:47 +01:00
|
|
|
from typing import List
|
|
|
|
|
2023-01-08 17:15:02 +01:00
|
|
|
from .factory import ProjectSupervisorFactory, YearGroupProjectSupervisorsFactory, \
|
2023-01-08 20:26:41 +01:00
|
|
|
StudentFactory, YearGroupStudentsFactory, GroupFactory
|
2023-01-06 22:35:47 +01:00
|
|
|
from ..app.dependencies import db
|
2023-01-08 17:15:02 +01:00
|
|
|
from ..app.project_supervisor.models import YearGroup, ProjectSupervisor
|
|
|
|
from ..app.students.models import Group, Student, YearGroupStudents
|
2023-01-06 22:35:47 +01:00
|
|
|
from ..app.base.mode import ModeGroups
|
|
|
|
|
|
|
|
|
|
|
|
def create_year_group(data: dict = None) -> YearGroup:
|
|
|
|
if data is None:
|
|
|
|
data = {'mode': ModeGroups.STATIONARY.value, 'name': '2022/2023'}
|
|
|
|
yg = YearGroup(**data)
|
|
|
|
db.session.add(yg)
|
|
|
|
db.session.commit()
|
|
|
|
return yg
|
|
|
|
|
|
|
|
|
|
|
|
def create_project_supervisors(yg: YearGroup, amount: int) -> List[ProjectSupervisorFactory]:
|
|
|
|
ps = [ProjectSupervisorFactory() for _ in range(amount)]
|
|
|
|
db.session.add_all(ps)
|
|
|
|
db.session.commit()
|
|
|
|
db.session.add_all(
|
2023-01-08 17:15:02 +01:00
|
|
|
[YearGroupProjectSupervisorsFactory(limit_group=3, 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()
|
|
|
|
db.session.add_all([YearGroupStudentsFactory(year_group_id=yg.id, student_index=s.index) for s in students])
|
|
|
|
db.session.commit()
|
|
|
|
return students
|
|
|
|
|
|
|
|
|
|
|
|
def create_student(data: dict, year_group_id: int) -> Student:
|
|
|
|
st = Student(**data)
|
|
|
|
db.session.add(st)
|
|
|
|
db.session.commit()
|
|
|
|
db.session.add(YearGroupStudents(year_group_id=year_group_id, student_index=st.index))
|
|
|
|
db.session.commit()
|
|
|
|
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
|