mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Remove GroupExperiment.customInit
This commit is contained in:
parent
86c7f6d915
commit
2f7d005ea4
4 changed files with 22 additions and 20 deletions
|
@ -571,7 +571,7 @@ class PartStudentView(SecureAdminModelView):
|
||||||
return PartStudent.part.has(Part.semester == userActiveSemester())
|
return PartStudent.part.has(Part.semester == userActiveSemester())
|
||||||
|
|
||||||
def on_model_change(self, form, model, is_created):
|
def on_model_change(self, form, model, is_created):
|
||||||
PartStudent.check(model.group, model.part)
|
PartStudent.check(model.part, model.group)
|
||||||
|
|
||||||
|
|
||||||
def partStudentQueryFactory():
|
def partStudentQueryFactory():
|
||||||
|
@ -1055,7 +1055,7 @@ class GroupExperimentView(SecureAdminModelView):
|
||||||
return GroupExperiment.group.has(Group.semester == userActiveSemester())
|
return GroupExperiment.group.has(Group.semester == userActiveSemester())
|
||||||
|
|
||||||
def customCreateModel(self, form):
|
def customCreateModel(self, form):
|
||||||
return GroupExperiment.customInit(semester_experiment=form.semester_experiment.data, group=form.group.data)
|
return GroupExperiment(semester_experiment=form.semester_experiment.data, group=form.group.data)
|
||||||
|
|
||||||
def on_model_change(self, form, model, is_created):
|
def on_model_change(self, form, model, is_created):
|
||||||
if is_created:
|
if is_created:
|
||||||
|
|
|
@ -243,7 +243,7 @@ def importFromFile(filePath):
|
||||||
dbGroupExperiments = {}
|
dbGroupExperiments = {}
|
||||||
for i, id in enumerate(groupExperiments["id"]):
|
for i, id in enumerate(groupExperiments["id"]):
|
||||||
id = int(id)
|
id = int(id)
|
||||||
dbGroupExperiment = GroupExperiment.customInit(
|
dbGroupExperiment = GroupExperiment(
|
||||||
semester_experiment=dbSemesterExperiments[int(groupExperiments["experiment_id"][i])],
|
semester_experiment=dbSemesterExperiments[int(groupExperiments["experiment_id"][i])],
|
||||||
group=dbGroups[int(groupExperiments["group_id"][i])],
|
group=dbGroups[int(groupExperiments["group_id"][i])],
|
||||||
)
|
)
|
||||||
|
|
|
@ -73,16 +73,16 @@ class PartStudent(db.Model):
|
||||||
db.UniqueConstraint(student_id, group_id),
|
db.UniqueConstraint(student_id, group_id),
|
||||||
)
|
)
|
||||||
|
|
||||||
def check(group, part):
|
def check(part, group):
|
||||||
if group is not None and group.program != part.program:
|
if group is not None and group.program != part.program:
|
||||||
raise DataBaseException(
|
raise DataBaseException(
|
||||||
f"Group's program {group.program} and student part's program {part.program} do not match!"
|
f"Group's program {group.program} and student part's program {part.program} do not match!"
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, student, part, group=None):
|
||||||
PartStudent.check(kwargs.get("group"), kwargs["part"])
|
PartStudent.check(part, group)
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(student=student, part=part, group=group)
|
||||||
|
|
||||||
def customUpdate(self, group, final_part_mark):
|
def customUpdate(self, group, final_part_mark):
|
||||||
Part.check(group, self.part)
|
Part.check(group, self.part)
|
||||||
|
@ -176,11 +176,15 @@ class Group(db.Model):
|
||||||
.order_by(Group.number.desc())
|
.order_by(Group.number.desc())
|
||||||
.first()
|
.first()
|
||||||
)
|
)
|
||||||
lastTakenGroupNumber = (groupWithHighestNumber and groupWithHighestNumber.number) or 0
|
|
||||||
|
if groupWithHighestNumber is not None:
|
||||||
|
number = groupWithHighestNumber.number + 1
|
||||||
|
else:
|
||||||
|
number = 1
|
||||||
|
|
||||||
return Group(
|
return Group(
|
||||||
program=program,
|
program=program,
|
||||||
number=lastTakenGroupNumber + 1,
|
number=number,
|
||||||
part_students=part_students,
|
part_students=part_students,
|
||||||
semester=semester,
|
semester=semester,
|
||||||
)
|
)
|
||||||
|
@ -209,22 +213,20 @@ class GroupExperiment(db.Model):
|
||||||
|
|
||||||
__table_args__ = (db.UniqueConstraint(semester_experiment_id, group_id),)
|
__table_args__ = (db.UniqueConstraint(semester_experiment_id, group_id),)
|
||||||
|
|
||||||
def customInit(semester_experiment, group):
|
def __init__(self, semester_experiment, group):
|
||||||
for partStudent in group.part_students:
|
for partStudent in group.part_students:
|
||||||
student = partStudent.student
|
student = partStudent.student
|
||||||
for partStudent in student.part_students:
|
for partStudent in student.part_students:
|
||||||
for experimentMark in partStudent.experiment_marks:
|
for experimentMark in partStudent.experiment_marks:
|
||||||
if experimentMark.group_experiment.semester_experiment.experiment == semester_experiment.experiment:
|
if experimentMark.group_experiment.semester_experiment.experiment == semester_experiment.experiment:
|
||||||
raise Exception(
|
raise DataBaseException(
|
||||||
f"{student} has already done {semester_experiment.experiment} in {partStudent.part} and had {experimentMark}!"
|
f"{student} has already done {semester_experiment.experiment} in {partStudent.part} and had {experimentMark}!"
|
||||||
)
|
)
|
||||||
|
|
||||||
groupExperiment = GroupExperiment(semester_experiment=semester_experiment, group=group)
|
super().__init__(semester_experiment=semester_experiment, group=group)
|
||||||
|
|
||||||
for partStudent in group.part_students:
|
for partStudent in group.part_students:
|
||||||
db.session.add(ExperimentMark.customInit(part_student=partStudent, group_experiment=groupExperiment))
|
db.session.add(ExperimentMark.customInit(part_student=partStudent, group_experiment=self))
|
||||||
|
|
||||||
return groupExperiment
|
|
||||||
|
|
||||||
def repr(self):
|
def repr(self):
|
||||||
return f"SemExp {self.semester_experiment.repr()}; Gr {self.group.repr()}"
|
return f"SemExp {self.semester_experiment.repr()}; Gr {self.group.repr()}"
|
||||||
|
@ -372,16 +374,16 @@ class Appointment(db.Model):
|
||||||
semesterExperimentAssistants = semesterExperiment.assistants
|
semesterExperimentAssistants = semesterExperiment.assistants
|
||||||
|
|
||||||
if not semesterExperimentAssistants:
|
if not semesterExperimentAssistants:
|
||||||
raise Exception(f"{semesterExperiment} does not have assistants yet!")
|
raise DataBaseException(f"{semesterExperiment} does not have assistants yet!")
|
||||||
|
|
||||||
if assistant:
|
if assistant:
|
||||||
if assistant not in semesterExperimentAssistants:
|
if assistant not in semesterExperimentAssistants:
|
||||||
raise Exception(f"{assistant} not responsible for {semesterExperiment}!")
|
raise DataBaseException(f"{assistant} not responsible for {semesterExperiment}!")
|
||||||
else:
|
else:
|
||||||
if len(semesterExperimentAssistants) == 1:
|
if len(semesterExperimentAssistants) == 1:
|
||||||
assistant = semesterExperimentAssistants[0]
|
assistant = semesterExperimentAssistants[0]
|
||||||
else:
|
else:
|
||||||
raise Exception(
|
raise DataBaseException(
|
||||||
f"Experiment {semesterExperiment} has more than one assistant. You have to assign one of these assistants: {semesterExperimentAssistants}"
|
f"Experiment {semesterExperiment} has more than one assistant. You have to assign one of these assistants: {semesterExperimentAssistants}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -92,8 +92,8 @@ def main():
|
||||||
db.session.add(sx1)
|
db.session.add(sx1)
|
||||||
db.session.add(sx2)
|
db.session.add(sx2)
|
||||||
|
|
||||||
gx1 = GroupExperiment.customInit(semester_experiment=sx1, group=g1)
|
gx1 = GroupExperiment(semester_experiment=sx1, group=g1)
|
||||||
gx2 = GroupExperiment.customInit(semester_experiment=sx2, group=g2)
|
gx2 = GroupExperiment(semester_experiment=sx2, group=g2)
|
||||||
|
|
||||||
db.session.add(gx1)
|
db.session.add(gx1)
|
||||||
db.session.add(gx2)
|
db.session.add(gx2)
|
||||||
|
|
Loading…
Reference in a new issue