1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-12-20 23:41:20 +00:00

Remove PartStudent.customInit

This commit is contained in:
Mo 2022-05-15 20:05:00 +02:00
parent 5fd9154901
commit 86c7f6d915
4 changed files with 10 additions and 10 deletions

View file

@ -348,7 +348,7 @@ class SemesterView(SecureAdminModelView):
] ]
def customCreateModel(self, form): def customCreateModel(self, form):
return Semester.customInitFromOldSemester( return Semester.initFromOldSemester(
label=form.label.data, label=form.label.data,
year=form.year.data, year=form.year.data,
oldSemester=userActiveSemester(), oldSemester=userActiveSemester(),

View file

@ -202,7 +202,7 @@ def importFromFile(filePath):
for i, studentNumber in enumerate(partStudents["student_number"]): for i, studentNumber in enumerate(partStudents["student_number"]):
studentNumber = int(studentNumber) studentNumber = int(studentNumber)
dbPartStudent = PartStudent.customInit( dbPartStudent = PartStudent(
student=dbStudents[studentNumber], student=dbStudents[studentNumber],
part=dbParts[int(partStudents["part_id"][i])], part=dbParts[int(partStudents["part_id"][i])],
group=dbGroups[int(partStudents["group_id"][i])], group=dbGroups[int(partStudents["group_id"][i])],

View file

@ -74,15 +74,15 @@ class PartStudent(db.Model):
) )
def check(group, part): def check(group, part):
if group 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 customInit(student, part, group=None): def __init__(self, *args, **kwargs):
PartStudent.check(group, part) PartStudent.check(kwargs.get("group"), kwargs["part"])
return PartStudent(student=student, part=part, group=group) super().__init__(*args, **kwargs)
def customUpdate(self, group, final_part_mark): def customUpdate(self, group, final_part_mark):
Part.check(group, self.part) Part.check(group, self.part)
@ -442,7 +442,7 @@ class Semester(db.Model):
__table_args__ = (db.UniqueConstraint(label, year),) __table_args__ = (db.UniqueConstraint(label, year),)
def customInitFromOldSemester(label, year, oldSemester, transferParts, transferAssistants): def initFromOldSemester(label, year, oldSemester, transferParts, transferAssistants):
semester = Semester(label=label, year=year) semester = Semester(label=label, year=year)
if transferParts: if transferParts:

View file

@ -49,9 +49,9 @@ def main():
db.session.add(student2) db.session.add(student2)
db.session.add(student3) db.session.add(student3)
ps1 = PartStudent.customInit(student=student1, part=part1) ps1 = PartStudent(student=student1, part=part1)
ps2 = PartStudent.customInit(student=student2, part=part1) ps2 = PartStudent(student=student2, part=part1)
ps3 = PartStudent.customInit(student=student3, part=part2) ps3 = PartStudent(student=student3, part=part2)
db.session.add(ps1) db.session.add(ps1)
db.session.add(ps2) db.session.add(ps2)