mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Added checkAndInit to GroupExperiment and repr() to all Models
This commit is contained in:
parent
5212eb8ee6
commit
f28f9b64fb
4 changed files with 103 additions and 38 deletions
|
@ -51,6 +51,8 @@ This URL leads to the home page where you can login with this testing admin acco
|
||||||
|
|
||||||
# To-Do:
|
# To-Do:
|
||||||
- Rest of admin model views
|
- Rest of admin model views
|
||||||
|
- Calculate final experiment and part mark
|
||||||
|
- Check if passed in GroupExperiment.checkAndInit
|
||||||
- Assistants space
|
- Assistants space
|
||||||
- Deactivate assistants account after a while if not assigned to experiments
|
- Deactivate assistants account after a while if not assigned to experiments
|
||||||
- Homepage text changeable
|
- Homepage text changeable
|
||||||
|
|
|
@ -159,11 +159,11 @@ class SemesterView(SecureModelView):
|
||||||
|
|
||||||
setUserActiveSemester(model.id)
|
setUserActiveSemester(model.id)
|
||||||
|
|
||||||
|
try:
|
||||||
if form.transfer_parts.data:
|
if form.transfer_parts.data:
|
||||||
model.transferPartsFrom(oldSemester)
|
model.transferPartsFrom(oldSemester)
|
||||||
|
|
||||||
if form.transfer_semester_experiments.data:
|
if form.transfer_semester_experiments.data:
|
||||||
try:
|
|
||||||
for semesterExperiment in oldSemester.semester_experiments:
|
for semesterExperiment in oldSemester.semester_experiments:
|
||||||
newSemesterExperiment = SemesterExperiment(
|
newSemesterExperiment = SemesterExperiment(
|
||||||
experiment=semesterExperiment.experiment, semester=userActiveSemester()
|
experiment=semesterExperiment.experiment, semester=userActiveSemester()
|
||||||
|
@ -171,6 +171,7 @@ class SemesterView(SecureModelView):
|
||||||
if form.transfer_assistants.data:
|
if form.transfer_assistants.data:
|
||||||
newSemesterExperiment.assistants = semesterExperiment.assistants
|
newSemesterExperiment.assistants = semesterExperiment.assistants
|
||||||
self.session.add(newSemesterExperiment)
|
self.session.add(newSemesterExperiment)
|
||||||
|
|
||||||
self.session.commit()
|
self.session.commit()
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
flash(ex, "error")
|
flash(ex, "error")
|
||||||
|
@ -292,7 +293,7 @@ class GroupView(SecureModelView):
|
||||||
|
|
||||||
form = EditForm
|
form = EditForm
|
||||||
|
|
||||||
column_list = ["number", "part", "part_students"]
|
column_list = ["number", "part", "part_students", "group_experiments"]
|
||||||
column_filters = ["number", "part"]
|
column_filters = ["number", "part"]
|
||||||
|
|
||||||
partStudentPartPartMismatchException = "Part and StudentParts part don't match!"
|
partStudentPartPartMismatchException = "Part and StudentParts part don't match!"
|
||||||
|
@ -429,7 +430,9 @@ class GroupExperimentView(SecureModelView):
|
||||||
|
|
||||||
def create_model(self, form):
|
def create_model(self, form):
|
||||||
try:
|
try:
|
||||||
model = GroupExperiment(semester_experiment=form.semester_experiment.data, group=form.group.data)
|
model = GroupExperiment.checkAndInit(
|
||||||
|
semester_experiment=form.semester_experiment.data, group=form.group.data
|
||||||
|
)
|
||||||
|
|
||||||
self.session.add(model)
|
self.session.add(model)
|
||||||
|
|
||||||
|
@ -466,6 +469,7 @@ class GroupExperimentView(SecureModelView):
|
||||||
|
|
||||||
self.session.rollback()
|
self.session.rollback()
|
||||||
else:
|
else:
|
||||||
|
if model.appointments:
|
||||||
flash(f"Appointments {model.appointments} added.", "success")
|
flash(f"Appointments {model.appointments} added.", "success")
|
||||||
|
|
||||||
self.after_model_change(form, model, True)
|
self.after_model_change(form, model, True)
|
||||||
|
|
|
@ -27,8 +27,11 @@ class Student(db.Model):
|
||||||
note = db.Column(db.Text, nullable=True)
|
note = db.Column(db.Text, nullable=True)
|
||||||
part_students = db.relationship("PartStudent", backref="student", lazy=True)
|
part_students = db.relationship("PartStudent", backref="student", lazy=True)
|
||||||
|
|
||||||
|
def repr(self):
|
||||||
|
return f"{self.first_name} {self.last_name}"
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<Student: {self.first_name} {self.last_name}>"
|
return f"<STD {self.repr()}>"
|
||||||
|
|
||||||
|
|
||||||
class PartStudent(db.Model):
|
class PartStudent(db.Model):
|
||||||
|
@ -40,8 +43,11 @@ class PartStudent(db.Model):
|
||||||
group_id = db.Column(db.Integer, db.ForeignKey("group.id"), nullable=True)
|
group_id = db.Column(db.Integer, db.ForeignKey("group.id"), nullable=True)
|
||||||
experiment_marks = db.relationship("ExperimentMark", backref="part_student", lazy=True)
|
experiment_marks = db.relationship("ExperimentMark", backref="part_student", lazy=True)
|
||||||
|
|
||||||
|
def repr(self):
|
||||||
|
return f"{self.student.repr()} {self.part.repr()}"
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<PartStudent: {self.student} in {self.part}>"
|
return f"<PARTSTD {self.repr()}>"
|
||||||
|
|
||||||
|
|
||||||
class Group(db.Model):
|
class Group(db.Model):
|
||||||
|
@ -51,8 +57,11 @@ class Group(db.Model):
|
||||||
part_students = db.relationship("PartStudent", backref="group", lazy=True)
|
part_students = db.relationship("PartStudent", backref="group", lazy=True)
|
||||||
group_experiments = db.relationship("GroupExperiment", backref="group", lazy=True)
|
group_experiments = db.relationship("GroupExperiment", backref="group", lazy=True)
|
||||||
|
|
||||||
|
def repr(self):
|
||||||
|
return f"{self.number} {self.part.repr()}"
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<Group {self.number} {Part.query.get(self.part_id)}>"
|
return f"<GR {self.repr()}>"
|
||||||
|
|
||||||
|
|
||||||
class GroupExperiment(db.Model):
|
class GroupExperiment(db.Model):
|
||||||
|
@ -63,6 +72,30 @@ class GroupExperiment(db.Model):
|
||||||
appointments = db.relationship("Appointment", backref="group_experiment", lazy=True)
|
appointments = db.relationship("Appointment", backref="group_experiment", lazy=True)
|
||||||
experiment_marks = db.relationship("ExperimentMark", backref="group_experiment", lazy=True)
|
experiment_marks = db.relationship("ExperimentMark", backref="group_experiment", lazy=True)
|
||||||
|
|
||||||
|
def repr(self):
|
||||||
|
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:
|
||||||
|
student = partStudent.student
|
||||||
|
for partStudent in student.part_students:
|
||||||
|
for experimentMark in partStudent.experiment_marks:
|
||||||
|
if (
|
||||||
|
experimentMark.group_experiment.semester_experiment.experiment == semester_experiment.experiment
|
||||||
|
): # TODO Check if passed
|
||||||
|
raise Exception(
|
||||||
|
f"{student} has already done {semester_experiment.experiment} in {partStudent.part}!"
|
||||||
|
)
|
||||||
|
|
||||||
|
for groupExperiment in group.group_experiments:
|
||||||
|
if groupExperiment.semester_experiment == semester_experiment: # TODO: What if did not pass?
|
||||||
|
raise Exception(f"{group} already has {semester_experiment}!")
|
||||||
|
|
||||||
|
return GroupExperiment(semester_experiment=semester_experiment, group=group)
|
||||||
|
|
||||||
|
|
||||||
class Experiment(db.Model):
|
class Experiment(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
@ -80,8 +113,11 @@ class Experiment(db.Model):
|
||||||
final_weighting = db.Column(db.Float, nullable=False)
|
final_weighting = db.Column(db.Float, nullable=False)
|
||||||
semester_experiments = db.relationship("SemesterExperiment", backref="experiment", lazy=True)
|
semester_experiments = db.relationship("SemesterExperiment", backref="experiment", lazy=True)
|
||||||
|
|
||||||
|
def repr(self):
|
||||||
|
return f"{self.number}"
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<Exp {self.number}>"
|
return f"<EXP {self.repr()}>"
|
||||||
|
|
||||||
|
|
||||||
# Helper table for the many to many relationship between Assistant and SemesterExperiment
|
# Helper table for the many to many relationship between Assistant and SemesterExperiment
|
||||||
|
@ -102,6 +138,12 @@ class SemesterExperiment(db.Model):
|
||||||
)
|
)
|
||||||
group_experiments = db.relationship("GroupExperiment", backref="semester_experiment", lazy=True)
|
group_experiments = db.relationship("GroupExperiment", backref="semester_experiment", lazy=True)
|
||||||
|
|
||||||
|
def repr(self):
|
||||||
|
return f"{self.experiment.repr()} {self.semester.repr()}"
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"<SEMEXP {self.repr()}>"
|
||||||
|
|
||||||
|
|
||||||
class Assistant(db.Model):
|
class Assistant(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
@ -116,8 +158,11 @@ class Assistant(db.Model):
|
||||||
appointments = db.relationship("Appointment", backref="assistant", lazy=True)
|
appointments = db.relationship("Appointment", backref="assistant", lazy=True)
|
||||||
experiment_marks = db.relationship("ExperimentMark", backref="assistant", lazy=True)
|
experiment_marks = db.relationship("ExperimentMark", backref="assistant", lazy=True)
|
||||||
|
|
||||||
|
def repr(self):
|
||||||
|
return f"{self.first_name} {self.last_name}"
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<Assistant: {self.first_name} {self.last_name}>"
|
return f"<ASST: {self.repr()}>"
|
||||||
|
|
||||||
|
|
||||||
class Appointment(db.Model):
|
class Appointment(db.Model):
|
||||||
|
@ -127,6 +172,12 @@ 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 repr(self):
|
||||||
|
return f"{self.date} {self.group_experiment.repr()}"
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"<APPT {self.repr()}>"
|
||||||
|
|
||||||
|
|
||||||
class Part(db.Model):
|
class Part(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
@ -135,8 +186,11 @@ class Part(db.Model):
|
||||||
part_students = db.relationship("PartStudent", backref="part", lazy=True)
|
part_students = db.relationship("PartStudent", backref="part", lazy=True)
|
||||||
groups = db.relationship("Group", backref="part", lazy=True)
|
groups = db.relationship("Group", backref="part", lazy=True)
|
||||||
|
|
||||||
|
def repr(self):
|
||||||
|
return f"{self.label} {self.semester.repr()}"
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<Part {self.label} {Semester.query.get(self.semester_id).label}>"
|
return f"<PART {self.repr()}>"
|
||||||
|
|
||||||
|
|
||||||
class Semester(db.Model):
|
class Semester(db.Model):
|
||||||
|
@ -145,11 +199,13 @@ class Semester(db.Model):
|
||||||
parts = db.relationship("Part", backref="semester", lazy=True)
|
parts = db.relationship("Part", backref="semester", lazy=True)
|
||||||
semester_experiments = db.relationship("SemesterExperiment", backref="semester", lazy=True)
|
semester_experiments = db.relationship("SemesterExperiment", backref="semester", lazy=True)
|
||||||
|
|
||||||
|
def repr(self):
|
||||||
|
return f"{self.label}"
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<{self.label}>"
|
return f"<SEM {self.repr()}>"
|
||||||
|
|
||||||
def transferPartsFrom(self, oldSemester):
|
def transferPartsFrom(self, oldSemester):
|
||||||
try:
|
|
||||||
if oldSemester:
|
if oldSemester:
|
||||||
partLabels = [part.label for part in oldSemester.parts]
|
partLabels = [part.label for part in oldSemester.parts]
|
||||||
else:
|
else:
|
||||||
|
@ -158,15 +214,6 @@ class Semester(db.Model):
|
||||||
for partLabel in partLabels:
|
for partLabel in partLabels:
|
||||||
db.session.add(Part(label=partLabel, semester=self))
|
db.session.add(Part(label=partLabel, semester=self))
|
||||||
|
|
||||||
db.session.commit()
|
|
||||||
except Exception as ex:
|
|
||||||
if has_request_context():
|
|
||||||
flash(ex, "error")
|
|
||||||
else:
|
|
||||||
print(ex)
|
|
||||||
|
|
||||||
db.session.rollback()
|
|
||||||
|
|
||||||
|
|
||||||
class ExperimentMark(db.Model):
|
class ExperimentMark(db.Model):
|
||||||
# A mark for a student after a specific experiment
|
# A mark for a student after a specific experiment
|
||||||
|
@ -177,17 +224,29 @@ class ExperimentMark(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(
|
assistant_id = db.Column(
|
||||||
db.Integer, db.ForeignKey("assistant.id"), nullable=True
|
db.Integer, db.ForeignKey("assistant.id"), nullable=True
|
||||||
) # The assistant who gives the mark
|
) # The assistant who gave the mark
|
||||||
|
|
||||||
|
def repr(self):
|
||||||
|
return f"Oral {round(self.oral_mark, 1)}; Prot {round(self.protocol_mark, 1)}"
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"<EXPMARL {self.repr()}>"
|
||||||
|
|
||||||
|
|
||||||
class User(db.Model, FsUserMixin):
|
class User(db.Model, FsUserMixin):
|
||||||
assistant = db.relationship("Assistant", backref="user", lazy=True, uselist=False)
|
assistant = db.relationship("Assistant", backref="user", lazy=True, uselist=False)
|
||||||
active_semester_id = db.Column(db.Integer, nullable=True)
|
active_semester_id = db.Column(db.Integer, nullable=True)
|
||||||
|
|
||||||
|
def repr(self):
|
||||||
|
return f"{self.email}"
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<User {self.email}>"
|
return f"<USR {self.repr()}>"
|
||||||
|
|
||||||
|
|
||||||
class Role(db.Model, FsRoleMixin):
|
class Role(db.Model, FsRoleMixin):
|
||||||
|
def repr(self):
|
||||||
|
return f"{self.name}"
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<{self.name}>"
|
return f"<ROLE {self.repr()}>"
|
||||||
|
|
|
@ -16,7 +16,7 @@ with app.app_context():
|
||||||
db.session.add(sem2)
|
db.session.add(sem2)
|
||||||
|
|
||||||
sem1.transferPartsFrom(None)
|
sem1.transferPartsFrom(None)
|
||||||
sem2.transferPartsFrom(None)
|
sem2.transferPartsFrom(sem1)
|
||||||
|
|
||||||
parta1 = sem2.parts[0]
|
parta1 = sem2.parts[0]
|
||||||
partb2 = sem2.parts[1]
|
partb2 = sem2.parts[1]
|
||||||
|
|
Loading…
Reference in a new issue