mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-11-08 21:21:06 +00:00
Big changes to the database, mainly due to adding Program
This commit is contained in:
parent
b2655e2023
commit
605edeecca
5 changed files with 84 additions and 38 deletions
File diff suppressed because one or more lines are too long
|
@ -489,7 +489,13 @@ class AppointmentView(SecureModelView):
|
|||
|
||||
form = CreateForm
|
||||
|
||||
column_filters = ["date", "special", "group_experiment.group", "group_experiment.group.part", "assistant"]
|
||||
column_filters = [
|
||||
"date",
|
||||
"special",
|
||||
"group_experiment.group",
|
||||
"group_experiment.semester_experiment.experiment",
|
||||
"assistant",
|
||||
]
|
||||
|
||||
def queryFilter(self):
|
||||
return Appointment.group_experiment_id.in_(
|
||||
|
|
|
@ -25,6 +25,7 @@ class Student(db.Model):
|
|||
bachelor_thesis = db.Column(db.String, nullable=True)
|
||||
bachelor_thesis_work_group = db.Column(db.String, nullable=True)
|
||||
note = db.Column(db.Text, nullable=True)
|
||||
|
||||
part_students = db.relationship("PartStudent", backref="student", lazy=True)
|
||||
|
||||
def repr(self):
|
||||
|
@ -43,9 +44,11 @@ class PartStudent(db.Model):
|
|||
db.CheckConstraint("final_part_mark < 16"),
|
||||
nullable=True,
|
||||
)
|
||||
|
||||
student_id = db.Column(db.Integer, db.ForeignKey("student.id"), nullable=False)
|
||||
part_id = db.Column(db.Integer, db.ForeignKey("part.id"), nullable=False)
|
||||
group_id = db.Column(db.Integer, db.ForeignKey("group.id"), nullable=True)
|
||||
|
||||
experiment_marks = db.relationship("ExperimentMark", backref="part_student", lazy=True)
|
||||
|
||||
__table_args__ = (
|
||||
|
@ -63,24 +66,28 @@ class PartStudent(db.Model):
|
|||
class Group(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
number = db.Column(db.Integer, db.CheckConstraint("number > 0"), nullable=False)
|
||||
part_id = db.Column(db.Integer, db.ForeignKey("part.id"), nullable=False)
|
||||
|
||||
semester_id = db.Column(db.Integer, db.ForeignKey("semester.id"), nullable=False)
|
||||
program_id = db.Column(db.Integer, db.ForeignKey("program.id", nullable=False))
|
||||
|
||||
part_students = db.relationship("PartStudent", backref="group", lazy=True)
|
||||
group_experiments = db.relationship("GroupExperiment", backref="group", lazy=True)
|
||||
|
||||
__table_args__ = (db.UniqueConstraint(number, part_id),)
|
||||
__table_args__ = (db.UniqueConstraint(number, semester_id, program_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
|
||||
def customInit(semester, program, partStudents):
|
||||
orderedGroups = Group.query.filter(Group.semester == semester, Group.program == program).order_by(Group.number)
|
||||
lastTakenGroupNumber = orderedGroups[-1].number if orderedPartGroups.count() > 0 else 0
|
||||
|
||||
return Group(
|
||||
program=program,
|
||||
number=lastTakenGroupNumber + 1,
|
||||
part_students=partStudents,
|
||||
part=part,
|
||||
semester=semester,
|
||||
)
|
||||
|
||||
def repr(self):
|
||||
return f"{self.number} {self.part.repr()}"
|
||||
return f"{self.number} {self.program.repr()} {self.semester.repr()}"
|
||||
|
||||
def __repr__(self):
|
||||
return f"<GR {self.repr()}>"
|
||||
|
@ -89,8 +96,10 @@ class Group(db.Model):
|
|||
class GroupExperiment(db.Model):
|
||||
# An experiment specified to a group
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
|
||||
semester_experiment_id = db.Column(db.Integer, db.ForeignKey("semester_experiment.id"), nullable=False)
|
||||
group_id = db.Column(db.Integer, db.ForeignKey("group.id"), nullable=False)
|
||||
|
||||
appointments = db.relationship("Appointment", backref="group_experiment", lazy=True)
|
||||
experiment_marks = db.relationship("ExperimentMark", backref="group_experiment", lazy=True)
|
||||
|
||||
|
@ -126,15 +135,16 @@ class GroupExperiment(db.Model):
|
|||
|
||||
class Experiment(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
label = db.Column(db.String(20), nullable=False, unique=True)
|
||||
number = db.Column(db.Integer, db.CheckConstraint("number > 0"), nullable=False)
|
||||
title = db.Column(db.String(200), nullable=False)
|
||||
description = db.Column(db.Text, nullable=True)
|
||||
wiki_link = db.Column(db.String(200), nullable=True)
|
||||
wiki_link = db.Column(db.String(300), nullable=True)
|
||||
room = db.Column(db.String(100), nullable=False)
|
||||
building = db.Column(db.String(100), nullable=False)
|
||||
responsibility = db.Column(db.String(200), nullable=True)
|
||||
duration_in_days = db.Column(db.Integer, db.CheckConstraint("duration_in_days > -1"), nullable=False)
|
||||
active = db.Column(db.Boolean, default=True, nullable=False)
|
||||
|
||||
oral_weighting = db.Column(
|
||||
db.Float, db.CheckConstraint("oral_weighting >= 0"), db.CheckConstraint("oral_weighting <= 1"), nullable=False
|
||||
)
|
||||
|
@ -147,10 +157,15 @@ class Experiment(db.Model):
|
|||
final_weighting = db.Column(
|
||||
db.Float, db.CheckConstraint("final_weighting >= 0"), db.CheckConstraint("final_weightin <= 1"), nullable=False
|
||||
)
|
||||
|
||||
program_id = db.Column(db.Integer, db.ForeignKey("program.id"), nullable=False)
|
||||
|
||||
semester_experiments = db.relationship("SemesterExperiment", backref="experiment", lazy=True)
|
||||
|
||||
__table_args__ = (db.UniqueConstraint(number, program_id),)
|
||||
|
||||
def repr(self):
|
||||
return f"{self.label}"
|
||||
return f"{self.number} {self.program.repr()}"
|
||||
|
||||
def __repr__(self):
|
||||
return f"<EXP {self.repr()}>"
|
||||
|
@ -167,8 +182,10 @@ experiment_assistant = db.Table(
|
|||
class SemesterExperiment(db.Model):
|
||||
# An experiment in a specific semester
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
|
||||
experiment_id = db.Column(db.Integer, db.ForeignKey("experiment.id"), nullable=False)
|
||||
semester_id = db.Column(db.Integer, db.ForeignKey("semester.id"), nullable=False)
|
||||
|
||||
assistants = db.relationship(
|
||||
"Assistant", secondary=experiment_assistant, lazy=True, backref=db.backref("semester_experiments", lazy=True)
|
||||
)
|
||||
|
@ -191,7 +208,9 @@ class Assistant(db.Model):
|
|||
mobile_phone_number = db.Column(db.String(50), nullable=True)
|
||||
room = db.Column(db.String(100), nullable=True)
|
||||
building = db.Column(db.String(100), nullable=True)
|
||||
|
||||
user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False, unique=True)
|
||||
|
||||
appointments = db.relationship("Appointment", backref="assistant", lazy=True)
|
||||
experiment_marks = db.relationship("ExperimentMark", backref="assistant", lazy=True)
|
||||
|
||||
|
@ -206,6 +225,7 @@ class Appointment(db.Model):
|
|||
id = db.Column(db.Integer, primary_key=True)
|
||||
date = db.Column(db.Date, nullable=False) # To be specified with the python package "datetime"
|
||||
special = db.Column(db.Boolean, default=False, nullable=False) # In the break or not
|
||||
|
||||
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)
|
||||
|
||||
|
@ -256,15 +276,17 @@ class Appointment(db.Model):
|
|||
|
||||
class Part(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
label = db.Column(db.String(100), nullable=False) # A/1, A/2, B/1, B/2
|
||||
semester_id = db.Column(db.Integer, db.ForeignKey("semester.id"), nullable=False)
|
||||
part_students = db.relationship("PartStudent", backref="part", lazy=True)
|
||||
groups = db.relationship("Group", backref="part", lazy=True)
|
||||
number = db.Column(db.Integer, db.CheckConstraint("number > 0"), nullable=False)
|
||||
|
||||
__table_args__ = (db.UniqueConstraint(label, semester_id),)
|
||||
program_id = db.Column(db.Integer, db.ForeignKey("program.id"), nullable=True)
|
||||
semester_id = db.Column(db.Integer, db.ForeignKey("semester.id"), nullable=False)
|
||||
|
||||
part_students = db.relationship("PartStudent", backref="part", lazy=True)
|
||||
|
||||
__table_args__ = (db.UniqueConstraint(program_id, number, semester_id),)
|
||||
|
||||
def repr(self):
|
||||
return f"{self.label} {self.semester.repr()}"
|
||||
return f"{self.program.repr()}{self.number} {self.semester.repr()}"
|
||||
|
||||
def __repr__(self):
|
||||
return f"<PART {self.repr()}>"
|
||||
|
@ -272,37 +294,40 @@ class Part(db.Model):
|
|||
|
||||
class Semester(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
label = db.Column(db.String(100), nullable=False, unique=True) # WS2122 for example
|
||||
label = db.Column(db.String(10), nullable=False)
|
||||
year = db.Column(db.Integer, db.CheckConstraint("year > 0"), db.CheckConstraint("year < 100"), nullalbe=False)
|
||||
|
||||
parts = db.relationship("Part", backref="semester", lazy=True)
|
||||
semester_experiments = db.relationship("SemesterExperiment", backref="semester", lazy=True)
|
||||
active_users = db.relationship("User", backref="active_semester", lazy=True)
|
||||
groups = db.relationship("Group", backref="semester", lazy=True)
|
||||
|
||||
__table_args__ = (db.UniqueConstraint(label, year),)
|
||||
|
||||
def repr(self):
|
||||
return f"{self.label}"
|
||||
return f"{self.label}{self.year}"
|
||||
|
||||
def __repr__(self):
|
||||
return f"<SEM {self.repr()}>"
|
||||
|
||||
def transferPartsFrom(self, oldSemester):
|
||||
if oldSemester:
|
||||
partLabels = [part.label for part in oldSemester.parts]
|
||||
else:
|
||||
partLabels = getConfig("defaultPartLabels")
|
||||
|
||||
for partLabel in partLabels:
|
||||
db.session.add(Part(label=partLabel, semester=self))
|
||||
for part in oldSemester.parts:
|
||||
db.session.add(Part(program=part.program, number=part.number, semester=self))
|
||||
|
||||
|
||||
class ExperimentMark(db.Model):
|
||||
# A mark for a student after a specific experiment
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
|
||||
oral_mark = db.Column(
|
||||
db.Integer, db.CheckConstraint("oral_mark > -1"), db.CheckConstraint("oral_mark < 16"), nullable=True
|
||||
)
|
||||
protocol_mark = db.Column(
|
||||
db.Integer, db.CheckConstraint("protocol_mark > -1"), db.CheckConstraint("protocol_mark < 16"), nullable=True
|
||||
)
|
||||
|
||||
edited_by_admin = db.Column(db.Boolean, default=False, nullable=True)
|
||||
|
||||
part_student_id = db.Column(db.Integer, db.ForeignKey("part_student.id"), nullable=False)
|
||||
group_experiment_id = db.Column(db.Integer, db.ForeignKey("group_experiment.id"), nullable=False)
|
||||
assistant_id = db.Column(
|
||||
|
@ -319,9 +344,10 @@ class ExperimentMark(db.Model):
|
|||
|
||||
|
||||
class User(db.Model, FsUserMixin):
|
||||
assistant = db.relationship("Assistant", backref="user", lazy=True, uselist=False)
|
||||
active_semester_id = db.Column(db.Integer, db.ForeignKey("semester.id"), nullable=True)
|
||||
|
||||
assistant = db.relationship("Assistant", backref="user", lazy=True, uselist=False)
|
||||
|
||||
def repr(self):
|
||||
return f"{self.email}"
|
||||
|
||||
|
@ -335,3 +361,17 @@ class Role(db.Model, FsRoleMixin):
|
|||
|
||||
def __repr__(self):
|
||||
return f"<ROLE {self.repr()}>"
|
||||
|
||||
|
||||
class Program(db.Model):
|
||||
label = db.Column(db.String(25), nullable=False)
|
||||
|
||||
parts = db.relationship("Part", backref="program", lazy=True)
|
||||
experiments = db.relationship("Experiment", backref="program", lazy=True)
|
||||
groups = db.relationship("Group", backref="program", lazy=True)
|
||||
|
||||
def repr(self):
|
||||
return f"{self.label}"
|
||||
|
||||
def __repr__(self):
|
||||
return f"<PROG {self.repr()}>"
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
{
|
||||
"defaultPartLabels": [
|
||||
"A/1",
|
||||
"A/2",
|
||||
"A/m",
|
||||
"B/1",
|
||||
"B/2"
|
||||
]
|
||||
}
|
11
testDB.py
11
testDB.py
|
@ -15,7 +15,16 @@ with app.app_context():
|
|||
db.session.add(sem1)
|
||||
db.session.add(sem2)
|
||||
|
||||
sem1.transferPartsFrom(None)
|
||||
partKwargs = [
|
||||
{"label": "BS", "number": 1},
|
||||
{"label": "BS", "number": 2},
|
||||
{"label": "BE", "number": 1},
|
||||
{"label": "MS", "number": 1},
|
||||
{"label": "MS", "number": 2},
|
||||
]
|
||||
for kwargs in partKwargs:
|
||||
db.session.add(Part(semester=sem1, **kwargs))
|
||||
|
||||
sem2.transferPartsFrom(sem1)
|
||||
|
||||
parta1 = sem2.parts[0]
|
||||
|
|
Loading…
Reference in a new issue