mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-11-08 21:21:06 +00:00
158 lines
7.1 KiB
Python
158 lines
7.1 KiB
Python
"""
|
|
See the file DB.drawio for the design of the database. It can be opened in the internet browser with the website:
|
|
https://app.diagrams.net
|
|
|
|
For more information about the implementation, see the part to Models in the documentation of Flask-SQLAlchemy:
|
|
https://flask-sqlalchemy.palletsprojects.com/en/2.x/models/
|
|
"""
|
|
|
|
# Imports
|
|
from flask_security.models.fsqla_v2 import FsUserMixin, FsRoleMixin
|
|
|
|
# Importing the database instance
|
|
from advlabdb import db
|
|
|
|
|
|
class Student(db.Model):
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
student_number = db.Column(db.Integer, nullable=False, unique=True)
|
|
first_name = db.Column(db.String(100), nullable=False)
|
|
last_name = db.Column(db.String(100), nullable=False)
|
|
email = db.Column(db.String(200), nullable=False, unique=True)
|
|
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):
|
|
return f"<{self.first_name} {self.last_name}>"
|
|
|
|
|
|
class PartStudent(db.Model):
|
|
# A student doing a specific part
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
final_part_mark = db.Column(db.Integer, 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)
|
|
|
|
|
|
class Group(db.Model):
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
number = db.Column(db.Integer, nullable=False)
|
|
part_id = db.Column(db.Integer, db.ForeignKey("part.id"), nullable=False)
|
|
part_students = db.relationship("PartStudent", backref="group", lazy=True)
|
|
group_experiments = db.relationship("GroupExperiment", backref="group", lazy=True)
|
|
|
|
|
|
class GroupExperiment(db.Model):
|
|
# An experiment specified to a group
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
part_experiment_id = db.Column(db.Integer, db.ForeignKey("part_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)
|
|
|
|
|
|
class Experiment(db.Model):
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
number = db.Column(db.Integer, nullable=False, unique=True)
|
|
name = db.Column(db.String(200), nullable=False)
|
|
description = db.Column(db.Text, 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, nullable=False)
|
|
deprecated = db.Column(db.Boolean, nullable=False, default=False) # To not be deleted!
|
|
oral_weighting = db.Column(db.Float, nullable=False)
|
|
protocol_weighting = db.Column(db.Float, nullable=False)
|
|
final_weighting = db.Column(db.Float, nullable=False)
|
|
part_experiments = db.relationship("PartExperiment", backref="experiment", lazy=True)
|
|
|
|
def __repr__(self):
|
|
return f"<{self.number}>"
|
|
|
|
|
|
# Helper table for the many to many relationship between Assistant and PartExperiment
|
|
experiment_assistant = db.Table("experiment_assistant",
|
|
db.Column("part_experiment_id", db.Integer, db.ForeignKey("part_experiment.id"),
|
|
primary_key=True),
|
|
db.Column("assistant_id", db.Integer, db.ForeignKey("assistant.id"),
|
|
primary_key=True))
|
|
|
|
|
|
class PartExperiment(db.Model):
|
|
# An experiment in a specific part
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
experiment_id = db.Column(db.Integer, db.ForeignKey("experiment.id"), nullable=False)
|
|
part_id = db.Column(db.Integer, db.ForeignKey("part.id"), nullable=False)
|
|
assistants = db.relationship("Assistant", secondary=experiment_assistant, lazy=True,
|
|
backref=db.backref("part_experiments", lazy=True))
|
|
group_experiments = db.relationship("GroupExperiment", backref="part_experiment", lazy=True)
|
|
|
|
|
|
class Assistant(db.Model):
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
first_name = db.Column(db.String(100), nullable=False)
|
|
last_name = db.Column(db.String(100), nullable=False)
|
|
email = db.Column(db.String(200), nullable=False)
|
|
phone_number = db.Column(db.String(50), nullable=True)
|
|
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)
|
|
appointments = db.relationship("Appointment", backref="assistant", lazy=True)
|
|
experiment_marks = db.relationship("ExperimentMark", backref="assistant", lazy=True)
|
|
|
|
def __repr__(self):
|
|
return f"<{self.first_name} {self.last_name}>"
|
|
|
|
|
|
class Appointment(db.Model):
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
date = db.Column(db.DateTime, nullable=False) # To be specified with the python package "datetime"
|
|
special = db.Column(db.Boolean, 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)
|
|
|
|
|
|
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_experiments = db.relationship("PartExperiment", backref="part", lazy=True)
|
|
part_students = db.relationship("PartStudent", backref="part", lazy=True)
|
|
groups = db.relationship("Group", backref="part", lazy=True)
|
|
|
|
|
|
class Semester(db.Model):
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
label = db.Column(db.String(100), nullable=False) # WS2122 for example
|
|
parts = db.relationship("Part", backref="semester", lazy=True)
|
|
|
|
def __repr__(self):
|
|
return f"<{self.label}>"
|
|
|
|
|
|
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, nullable=True)
|
|
protocol_mark = db.Column(db.Integer, 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(db.Integer, db.ForeignKey("assistant.id"),
|
|
nullable=True) # The assistant who gives the mark
|
|
|
|
|
|
class User(db.Model, FsUserMixin):
|
|
assistant = db.relationship("Assistant", backref="user", lazy=True, uselist=False)
|
|
|
|
def __repr__(self):
|
|
return f"<{self.email}>"
|
|
|
|
|
|
class Role(db.Model, FsRoleMixin):
|
|
def __repr__(self):
|
|
return f"<{self.name}>"
|