mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Added customInit
This commit is contained in:
parent
18257799c7
commit
b67ba46768
2 changed files with 47 additions and 37 deletions
|
@ -287,14 +287,7 @@ class GroupView(SecureModelView):
|
||||||
|
|
||||||
def create_model(self, form):
|
def create_model(self, form):
|
||||||
try:
|
try:
|
||||||
orderedPartGroups = Group.query.filter(Group.part == form.part.data).order_by(Group.number)
|
model = Group.customInit(form.part.data, form.part_students.data)
|
||||||
lastTakenGroupNumber = orderedPartGroups[-1].number if orderedPartGroups.count() > 0 else 0
|
|
||||||
|
|
||||||
model = Group(
|
|
||||||
number=lastTakenGroupNumber + 1,
|
|
||||||
part_students=form.part_students.data,
|
|
||||||
part=form.part.data,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.session.add(model)
|
self.session.add(model)
|
||||||
self.on_model_change(form, model, True)
|
self.on_model_change(form, model, True)
|
||||||
|
@ -416,35 +409,17 @@ class GroupExperimentView(SecureModelView):
|
||||||
|
|
||||||
def create_model(self, form):
|
def create_model(self, form):
|
||||||
try:
|
try:
|
||||||
model = GroupExperiment.checkAndInit(
|
model = GroupExperiment.customInit(semester_experiment=form.semester_experiment.data, group=form.group.data)
|
||||||
semester_experiment=form.semester_experiment.data, group=form.group.data
|
|
||||||
)
|
|
||||||
|
|
||||||
self.session.add(model)
|
self.session.add(model)
|
||||||
|
|
||||||
for appointmentDate, special, assistant in zip(
|
for date, special, assistant in zip(
|
||||||
[form.appointment1_date.data, form.appointment2_date.data],
|
[form.appointment1_date.data, form.appointment2_date.data],
|
||||||
[form.appointment1_special.data, form.appointment2_special.data],
|
[form.appointment1_special.data, form.appointment2_special.data],
|
||||||
[form.appointment1_assistant.data, form.appointment2_assistant.data],
|
[form.appointment1_assistant.data, form.appointment2_assistant.data],
|
||||||
):
|
):
|
||||||
if appointmentDate:
|
if date:
|
||||||
if assistant:
|
appointment = Appointment.customInit(date, special, assistant, model)
|
||||||
if assistant not in form.semester_experiment.data.assistants:
|
|
||||||
raise Exception(f"{assistant} not responsible for {form.semester_experiment.data}!")
|
|
||||||
else:
|
|
||||||
if len(form.semester_experiment.data.assistants) != 1:
|
|
||||||
raise Exception(
|
|
||||||
f"Experiment {form.semester_experiment.data} has more than one assistant. You have to assign one of these assistants: {form.semester_experiment.data.assistants}"
|
|
||||||
)
|
|
||||||
|
|
||||||
assistant = form.semester_experiment.data.assistants[0]
|
|
||||||
|
|
||||||
appointment = Appointment(
|
|
||||||
date=appointmentDate,
|
|
||||||
special=special,
|
|
||||||
group_experiment=model,
|
|
||||||
assistant=assistant,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.session.add(appointment)
|
self.session.add(appointment)
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,16 @@ class Group(db.Model):
|
||||||
|
|
||||||
__table_args__ = (db.UniqueConstraint(number, part_id),)
|
__table_args__ = (db.UniqueConstraint(number, part_id),)
|
||||||
|
|
||||||
|
def customInit(part, partStudents):
|
||||||
|
orderedPartGroups = Group.query.filter(Group.part == part).order_by(Group.number)
|
||||||
|
lastTakenGroupNumber = orderedPartGroups[-1].number if orderedPartGroups.count() > 0 else 0
|
||||||
|
|
||||||
|
return Group(
|
||||||
|
number=lastTakenGroupNumber + 1,
|
||||||
|
part_students=partStudents,
|
||||||
|
part=part,
|
||||||
|
)
|
||||||
|
|
||||||
def repr(self):
|
def repr(self):
|
||||||
return f"{self.number} {self.part.repr()}"
|
return f"{self.number} {self.part.repr()}"
|
||||||
|
|
||||||
|
@ -86,13 +96,7 @@ class GroupExperiment(db.Model):
|
||||||
|
|
||||||
__table_args__ = (db.UniqueConstraint(semester_experiment_id, group_id),)
|
__table_args__ = (db.UniqueConstraint(semester_experiment_id, group_id),)
|
||||||
|
|
||||||
def repr(self):
|
def customInit(semester_experiment, group):
|
||||||
return f"SemExp {self.semester_experiment.repr()}; Gr {self.group.repr()}"
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return f"<GREXP {self.repr()}>"
|
|
||||||
|
|
||||||
def checkAndInit(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:
|
||||||
|
@ -104,6 +108,12 @@ class GroupExperiment(db.Model):
|
||||||
|
|
||||||
return GroupExperiment(semester_experiment=semester_experiment, group=group)
|
return GroupExperiment(semester_experiment=semester_experiment, group=group)
|
||||||
|
|
||||||
|
def repr(self):
|
||||||
|
return f"SemExp {self.semester_experiment.repr()}; Gr {self.group.repr()}"
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"<GREXP {self.repr()}>"
|
||||||
|
|
||||||
|
|
||||||
class Experiment(db.Model):
|
class Experiment(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
@ -181,6 +191,31 @@ class Appointment(db.Model):
|
||||||
group_experiment_id = db.Column(db.Integer, db.ForeignKey("group_experiment.id"), nullable=False)
|
group_experiment_id = db.Column(db.Integer, db.ForeignKey("group_experiment.id"), nullable=False)
|
||||||
assistant_id = db.Column(db.Integer, db.ForeignKey("assistant.id"), nullable=False)
|
assistant_id = db.Column(db.Integer, db.ForeignKey("assistant.id"), nullable=False)
|
||||||
|
|
||||||
|
def customInit(date, special, assistant, groupExperiment):
|
||||||
|
semesterExperiment = groupExperiment.semester_experiment
|
||||||
|
semesterExperimentAssistants = semesterExperiment.assistants
|
||||||
|
|
||||||
|
if not semesterExperimentAssistants:
|
||||||
|
raise Exception(f"{semesterExperiment} has no assistants yet!")
|
||||||
|
|
||||||
|
if assistant:
|
||||||
|
if assistant not in semesterExperimentAssistants:
|
||||||
|
raise Exception(f"{assistant} not responsible for {semesterExperiment}!")
|
||||||
|
else:
|
||||||
|
if len(semesterExperimentAssistants) == 1:
|
||||||
|
assistant = semesterExperimentAssistants[0]
|
||||||
|
else:
|
||||||
|
raise Exception(
|
||||||
|
f"Experiment {semesterExperiment} has more than one assistant. You have to assign one of these assistants: {semesterExperimentAssistants}"
|
||||||
|
)
|
||||||
|
|
||||||
|
return Appointment(
|
||||||
|
date=date,
|
||||||
|
special=special,
|
||||||
|
group_experiment=groupExperiment,
|
||||||
|
assistant=assistant,
|
||||||
|
)
|
||||||
|
|
||||||
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