mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-11-08 21:21:06 +00:00
some checks and customInits
This commit is contained in:
parent
48dad91671
commit
53a14c0c40
1 changed files with 54 additions and 21 deletions
|
@ -57,6 +57,23 @@ class PartStudent(db.Model):
|
||||||
db.UniqueConstraint(student_id, group_id),
|
db.UniqueConstraint(student_id, group_id),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def check(group, part):
|
||||||
|
if group and group.program != part.program:
|
||||||
|
raise DataBaseException(
|
||||||
|
f"Group's program {group.program} and student part's program {part.program} do not match!"
|
||||||
|
)
|
||||||
|
|
||||||
|
def customInit(student, part, group=None):
|
||||||
|
PartStudent.check(group, part)
|
||||||
|
|
||||||
|
return PartStudent(student=student, part=part, group=group)
|
||||||
|
|
||||||
|
def customUpdate(self, group, final_part_mark):
|
||||||
|
Part.check(group, self.part)
|
||||||
|
|
||||||
|
self.group = group
|
||||||
|
self.final_part_mark = final_part_mark
|
||||||
|
|
||||||
def repr(self):
|
def repr(self):
|
||||||
return f"{self.student.repr()} {self.part.repr()}"
|
return f"{self.student.repr()} {self.part.repr()}"
|
||||||
|
|
||||||
|
@ -76,30 +93,46 @@ class Group(db.Model):
|
||||||
|
|
||||||
__table_args__ = (db.UniqueConstraint(number, semester_id, program_id),)
|
__table_args__ = (db.UniqueConstraint(number, semester_id, program_id),)
|
||||||
|
|
||||||
def checkPartStudents(partStudents):
|
def check(part_students, program=None):
|
||||||
if partStudents:
|
commonProgram = part_students[0].part.program
|
||||||
program = partStudents[0].part.program
|
if program and program != commonProgram:
|
||||||
semester = partStudents[0].part.semester
|
raise DataBaseException("Group's program and students' program mismatch!")
|
||||||
for partStudent in partStudents[1:]:
|
|
||||||
if partStudent.part.program != program:
|
|
||||||
raise DataBaseException(f"Part Students {partStudents} are not in the same program!")
|
|
||||||
|
|
||||||
if partStudent.part.semester != semester:
|
commonSemester = part_students[0].part.semester
|
||||||
raise DataBaseException(f"Part Students {partStudents} are not in the same semester!")
|
|
||||||
|
|
||||||
def customInit(semester, program, partStudents):
|
for partStudent in part_students[1:]:
|
||||||
checkPartStudents(partStudents)
|
if partStudent.part.program != commonProgram:
|
||||||
|
raise DataBaseException(f"Part Students {part_students} are not in the same program!")
|
||||||
|
|
||||||
orderedGroups = Group.query.filter(Group.semester == semester, Group.program == program).order_by(Group.number)
|
if partStudent.part.semester != commonSemester:
|
||||||
lastTakenGroupNumber = orderedGroups[-1].number if orderedPartGroups.count() > 0 else 0
|
raise DataBaseException(f"Part Students {part_students} are not in the same semester!")
|
||||||
|
|
||||||
|
def customInit(part_students):
|
||||||
|
Group.check(part_students)
|
||||||
|
|
||||||
|
semester = part_students[0].part.semester
|
||||||
|
program = part_students[0].part.program
|
||||||
|
|
||||||
|
lastTakenGroupNumber = (
|
||||||
|
Group.query.filter(Group.semester == semester, Group.program == program)
|
||||||
|
.order_by(Group.number.desc())
|
||||||
|
.first()
|
||||||
|
.number
|
||||||
|
or 0
|
||||||
|
)
|
||||||
|
|
||||||
return Group(
|
return Group(
|
||||||
program=program,
|
program=program,
|
||||||
number=lastTakenGroupNumber + 1,
|
number=lastTakenGroupNumber + 1,
|
||||||
part_students=partStudents,
|
part_students=part_students,
|
||||||
semester=semester,
|
semester=semester,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def customUpdate(self, part_students):
|
||||||
|
Group.check(part_students, self.program)
|
||||||
|
|
||||||
|
self.part_students = part_students
|
||||||
|
|
||||||
def repr(self):
|
def repr(self):
|
||||||
return f"{self.number} {self.program.repr()} {self.semester.repr()}"
|
return f"{self.number} {self.program.repr()} {self.semester.repr()}"
|
||||||
|
|
||||||
|
@ -169,7 +202,7 @@ class Experiment(db.Model):
|
||||||
nullable=False,
|
nullable=False,
|
||||||
)
|
)
|
||||||
final_weighting = db.Column(
|
final_weighting = db.Column(
|
||||||
db.Float, db.CheckConstraint("final_weighting >= 0"), db.CheckConstraint("final_weightin <= 1"), nullable=False
|
db.Float, db.CheckConstraint("final_weighting >= 0"), db.CheckConstraint("final_weighting <= 1"), nullable=False
|
||||||
)
|
)
|
||||||
|
|
||||||
program_id = db.Column(db.Integer, db.ForeignKey("program.id"), nullable=False)
|
program_id = db.Column(db.Integer, db.ForeignKey("program.id"), nullable=False)
|
||||||
|
@ -263,23 +296,23 @@ class Appointment(db.Model):
|
||||||
|
|
||||||
return assistant
|
return assistant
|
||||||
|
|
||||||
def customInit(date, special, assistant, groupExperiment):
|
def customInit(date, special, assistant, group_experiment):
|
||||||
assistant = Appointment.checkAndGetAssistant(assistant, groupExperiment)
|
assistant = Appointment.checkAndGetAssistant(assistant, group_experiment)
|
||||||
|
|
||||||
return Appointment(
|
return Appointment(
|
||||||
date=date,
|
date=date,
|
||||||
special=special,
|
special=special,
|
||||||
group_experiment=groupExperiment,
|
group_experiment=group_experiment,
|
||||||
assistant=assistant,
|
assistant=assistant,
|
||||||
)
|
)
|
||||||
|
|
||||||
def customUpdate(self, date, special, assistant, groupExperiment):
|
def customUpdate(self, date, special, assistant, group_experiment):
|
||||||
assistant = Appointment.checkAndGetAssistant(assistant, groupExperiment)
|
assistant = Appointment.checkAndGetAssistant(assistant, group_experiment)
|
||||||
|
|
||||||
self.date = date
|
self.date = date
|
||||||
self.special = special
|
self.special = special
|
||||||
self.assistant = assistant
|
self.assistant = assistant
|
||||||
self.group_experiment = groupExperiment
|
self.group_experiment = group_experiment
|
||||||
|
|
||||||
def repr(self):
|
def repr(self):
|
||||||
return f"{self.date} {self.group_experiment.repr()}"
|
return f"{self.date} {self.group_experiment.repr()}"
|
||||||
|
|
Loading…
Reference in a new issue