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-10 00:17:25 +01:00
|
|
|
StudentFactory, YearGroupStudentsFactory, GroupFactory, ExaminationScheduleFactory
|
2023-01-09 22:32:58 +01:00
|
|
|
from app.dependencies import db
|
|
|
|
from app.project_supervisor.models import YearGroup, ProjectSupervisor
|
|
|
|
from app.students.models import Group, Student, YearGroupStudents
|
2023-01-10 00:17:25 +01:00
|
|
|
from app.examination_schedule.models import ExaminationSchedule
|
2023-01-09 22:32:58 +01:00
|
|
|
from app.base.mode import ModeGroups
|
2023-01-06 22:35:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2023-01-09 22:56:46 +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-09 22:56:46 +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()
|
|
|
|
db.session.add_all([YearGroupStudentsFactory(year_group_id=yg.id, student_index=s.index) for s in students])
|
|
|
|
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:
|
|
|
|
db.session.add(YearGroupStudents(year_group_id=year_group_id, student_index=st.index))
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
def create_examination_schedules(yg: YearGroup, amount: int) -> List[ExaminationScheduleFactory]:
|
|
|
|
examination_schedules = [ExaminationScheduleFactory(year_group_id=yg.id) for _ in range(amount)]
|
|
|
|
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
|