mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Replace repr with str
This commit is contained in:
parent
f45b3fbc4d
commit
ecad30eb79
1 changed files with 85 additions and 74 deletions
|
@ -47,11 +47,11 @@ class Student(db.Model):
|
|||
|
||||
part_students = db.relationship("PartStudent", back_populates="student", lazy=True)
|
||||
|
||||
def repr(self):
|
||||
def str(self):
|
||||
return f"{self.first_name} {self.last_name}"
|
||||
|
||||
def __repr__(self):
|
||||
return f"<STD {self.repr()}>"
|
||||
def __str__(self):
|
||||
return self.str()
|
||||
|
||||
|
||||
class PartStudent(db.Model):
|
||||
|
@ -77,6 +77,12 @@ class PartStudent(db.Model):
|
|||
db.UniqueConstraint(student_id, group_id),
|
||||
)
|
||||
|
||||
def str(self):
|
||||
return f"{self.student.str()} {self.part}"
|
||||
|
||||
def __str__(self):
|
||||
return f"<{self.str()}>"
|
||||
|
||||
def check(part, group):
|
||||
if group is not None and group.program != part.program:
|
||||
raise DataBaseException(
|
||||
|
@ -134,12 +140,6 @@ class PartStudent(db.Model):
|
|||
else:
|
||||
flash(f"Final part mark did not change for {self} from {oldFinalPartMark}.", "warning")
|
||||
|
||||
def repr(self):
|
||||
return f"{self.student.repr()} {self.part.repr()}"
|
||||
|
||||
def __repr__(self):
|
||||
return f"<PARTSTD {self.repr()}>"
|
||||
|
||||
|
||||
class Group(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
|
@ -155,6 +155,15 @@ class Group(db.Model):
|
|||
|
||||
__table_args__ = (db.UniqueConstraint(number, semester_id, program_id),)
|
||||
|
||||
def str_without_semester(self):
|
||||
return f"{self.number} {self.program.str()}"
|
||||
|
||||
def str(self):
|
||||
return f"{self.str_without_semester()} {self.semester.str()}"
|
||||
|
||||
def __str__(self):
|
||||
return f"<{self.str()}>"
|
||||
|
||||
def check(part_students, program=None):
|
||||
commonProgram = part_students[0].part.program
|
||||
|
||||
|
@ -189,12 +198,6 @@ class Group(db.Model):
|
|||
semester=semester,
|
||||
)
|
||||
|
||||
def repr(self):
|
||||
return f"{self.number} {self.program.repr()} {self.semester.repr()}"
|
||||
|
||||
def __repr__(self):
|
||||
return f"<GR {self.repr()}>"
|
||||
|
||||
|
||||
class GroupExperiment(db.Model):
|
||||
# An experiment specified to a group
|
||||
|
@ -210,6 +213,12 @@ class GroupExperiment(db.Model):
|
|||
|
||||
__table_args__ = (db.UniqueConstraint(semester_experiment_id, group_id),)
|
||||
|
||||
def str(self):
|
||||
return f"<SemExp: {self.semester_experiment.str()} | Gr: {self.group.str()}>"
|
||||
|
||||
def __str__(self):
|
||||
return self.str()
|
||||
|
||||
def check(semester_experiment, group):
|
||||
for partStudent in group.part_students:
|
||||
student = partStudent.student
|
||||
|
@ -228,12 +237,6 @@ class GroupExperiment(db.Model):
|
|||
for partStudent in group.part_students:
|
||||
db.session.add(ExperimentMark(part_student=partStudent, group_experiment=self))
|
||||
|
||||
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):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
|
@ -256,11 +259,11 @@ class Experiment(db.Model):
|
|||
|
||||
__table_args__ = (db.UniqueConstraint(number, program_id),)
|
||||
|
||||
def repr(self):
|
||||
return f"{self.number} {self.program.repr()}"
|
||||
def str(self):
|
||||
return f"{self.number} {self.program.str()}"
|
||||
|
||||
def __repr__(self):
|
||||
return f"<EXP {self.repr()}>"
|
||||
def __str__(self):
|
||||
return f"<{self.str()}>"
|
||||
|
||||
|
||||
# Helper table for the many to many relationship between Assistant and SemesterExperiment
|
||||
|
@ -305,6 +308,15 @@ class SemesterExperiment(db.Model):
|
|||
|
||||
__table_args__ = (db.UniqueConstraint(experiment_id, semester_id),)
|
||||
|
||||
def str_without_semester(self):
|
||||
return f"{self.experiment.str()}"
|
||||
|
||||
def str(self):
|
||||
return f"{self.str_without_semester()} {self.semester.str()}"
|
||||
|
||||
def __str__(self):
|
||||
return f"<{self.str()}>"
|
||||
|
||||
def checkAndRoundWeightings(self):
|
||||
roundedOralWeighting = round(self.oral_weighting, 2)
|
||||
roundedProtocolWeighting = round(self.protocol_weighting, 2)
|
||||
|
@ -328,12 +340,6 @@ class SemesterExperiment(db.Model):
|
|||
for partStudent in groupExperiment.group.part_students:
|
||||
partStudent.checkThenSetFinalPartMark()
|
||||
|
||||
def repr(self):
|
||||
return f"{self.experiment.repr()} {self.semester.repr()}"
|
||||
|
||||
def __repr__(self):
|
||||
return f"<SEMEXP {self.repr()}>"
|
||||
|
||||
|
||||
class Assistant(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
|
@ -347,11 +353,11 @@ class Assistant(db.Model):
|
|||
appointments = db.relationship("Appointment", back_populates="assistant", lazy=True)
|
||||
experiment_marks = db.relationship("ExperimentMark", back_populates="assistant", lazy=True)
|
||||
|
||||
def repr(self):
|
||||
return f"{self.user.first_name} {self.user.last_name}"
|
||||
def str(self):
|
||||
return f"{self.user}"
|
||||
|
||||
def __repr__(self):
|
||||
return f"<ASST: {self.repr()}>"
|
||||
def __str__(self):
|
||||
return self.str()
|
||||
|
||||
|
||||
class Admin(db.Model):
|
||||
|
@ -362,11 +368,11 @@ class Admin(db.Model):
|
|||
|
||||
experiment_marks = db.relationship("ExperimentMark", back_populates="admin", lazy=True)
|
||||
|
||||
def repr(self):
|
||||
return f"{self.user.first_name} {self.user.last_name}"
|
||||
def str(self):
|
||||
return f"{self.user}"
|
||||
|
||||
def __repr__(self):
|
||||
return f"<ADMIN: {self.repr()}>"
|
||||
def __str__(self):
|
||||
return self.str()
|
||||
|
||||
|
||||
class Appointment(db.Model):
|
||||
|
@ -379,6 +385,12 @@ class Appointment(db.Model):
|
|||
assistant_id = db.Column(db.Integer, db.ForeignKey("assistant.id"), nullable=False)
|
||||
assistant = db.relationship("Assistant", back_populates="appointments")
|
||||
|
||||
def str(self):
|
||||
return f"{self.date} {self.group_experiment.str()}"
|
||||
|
||||
def __str__(self):
|
||||
return f"<{self.str()}>"
|
||||
|
||||
def checkAndGetAssistant(groupExperiment, assistant=None):
|
||||
semesterExperiment = groupExperiment.semester_experiment
|
||||
semesterExperimentAssistants = semesterExperiment.assistants
|
||||
|
@ -416,12 +428,6 @@ class Appointment(db.Model):
|
|||
self.special = special
|
||||
self.group_experiment = group_experiment
|
||||
|
||||
def repr(self):
|
||||
return f"{self.date} {self.group_experiment.repr()}"
|
||||
|
||||
def __repr__(self):
|
||||
return f"<APPT {self.repr()}>"
|
||||
|
||||
|
||||
class Part(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
|
@ -436,11 +442,14 @@ class Part(db.Model):
|
|||
|
||||
__table_args__ = (db.UniqueConstraint(program_id, number, semester_id),)
|
||||
|
||||
def repr(self):
|
||||
return f"{self.program.repr()}{self.number} {self.semester.repr()}"
|
||||
def str_without_semester(self):
|
||||
return f"{self.program.str()}{self.number}"
|
||||
|
||||
def __repr__(self):
|
||||
return f"<PART {self.repr()}>"
|
||||
def str(self):
|
||||
return f"{self.str_without_semester()} {self.semester.str()}"
|
||||
|
||||
def __str__(self):
|
||||
return f"<{self.str()}>"
|
||||
|
||||
|
||||
class Semester(db.Model):
|
||||
|
@ -455,6 +464,12 @@ class Semester(db.Model):
|
|||
|
||||
__table_args__ = (db.UniqueConstraint(label, year),)
|
||||
|
||||
def str(self):
|
||||
return f"{self.label}{self.year}"
|
||||
|
||||
def __str__(self):
|
||||
return self.str()
|
||||
|
||||
def __init__(self, label, year):
|
||||
last_semester = Semester.lastSemester()
|
||||
|
||||
|
@ -499,12 +514,6 @@ class Semester(db.Model):
|
|||
def lastSemester():
|
||||
return Semester.sortedSemestersStartingWithNewest(limit=1).first()
|
||||
|
||||
def repr(self):
|
||||
return f"{self.label}{self.year}"
|
||||
|
||||
def __repr__(self):
|
||||
return f"<SEM {self.repr()}>"
|
||||
|
||||
|
||||
class ExperimentMark(db.Model):
|
||||
# A mark for a student after a specific experiment
|
||||
|
@ -565,6 +574,14 @@ class ExperimentMark(db.Model):
|
|||
|
||||
__table_args__ = (db.UniqueConstraint(part_student_id, group_experiment_id),)
|
||||
|
||||
def str(self):
|
||||
return (
|
||||
f"<Final Exp Mark: {self.final_experiment_mark} | Exp: {self.group_experiment.semester_experiment.str()}>"
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.str()
|
||||
|
||||
def check(part_student, group_experiment):
|
||||
if not part_student.group:
|
||||
raise DataBaseException("The part student does not have a group yet!")
|
||||
|
@ -585,12 +602,6 @@ class ExperimentMark(db.Model):
|
|||
+ semesterExperiment.protocol_weighting * self.protocol_mark
|
||||
)
|
||||
|
||||
def repr(self):
|
||||
return f"Mark {self.final_experiment_mark}; Exp {self.group_experiment.semester_experiment.repr()}"
|
||||
|
||||
def __repr__(self):
|
||||
return f"<EXPMARK {self.repr()}>"
|
||||
|
||||
|
||||
class User(db.Model, FsUserMixin):
|
||||
first_name = db.Column(db.String(100), nullable=False)
|
||||
|
@ -606,6 +617,12 @@ class User(db.Model, FsUserMixin):
|
|||
admin = db.relationship("Admin", back_populates="user", lazy=False, uselist=False)
|
||||
assistant = db.relationship("Assistant", back_populates="user", lazy=True, uselist=False)
|
||||
|
||||
def str(self):
|
||||
return f"{self.first_name} {self.last_name}"
|
||||
|
||||
def __str__(self):
|
||||
return self.str()
|
||||
|
||||
def setActiveSemester(self, semester):
|
||||
if semester is None:
|
||||
flash(f"Can not change the active semester to None!", "error")
|
||||
|
@ -620,21 +637,15 @@ class User(db.Model, FsUserMixin):
|
|||
|
||||
db.session.rollback()
|
||||
else:
|
||||
flash(f"Active semester changed to {semester.repr()}!", "warning")
|
||||
|
||||
def repr(self):
|
||||
return f"{self.first_name} {self.last_name}"
|
||||
|
||||
def __repr__(self):
|
||||
return f"<USR {self.repr()}>"
|
||||
flash(f"Active semester changed to {semester}!", "warning")
|
||||
|
||||
|
||||
class Role(db.Model, FsRoleMixin):
|
||||
def repr(self):
|
||||
def str(self):
|
||||
return f"{self.name}"
|
||||
|
||||
def __repr__(self):
|
||||
return f"<ROLE {self.repr()}>"
|
||||
def __str__(self):
|
||||
return self.str()
|
||||
|
||||
|
||||
class Program(db.Model):
|
||||
|
@ -645,8 +656,8 @@ class Program(db.Model):
|
|||
experiments = db.relationship("Experiment", back_populates="program", lazy=True)
|
||||
groups = db.relationship("Group", back_populates="program", lazy=True)
|
||||
|
||||
def repr(self):
|
||||
def str(self):
|
||||
return f"{self.label}"
|
||||
|
||||
def __repr__(self):
|
||||
return f"<PROG {self.repr()}>"
|
||||
def __str__(self):
|
||||
return self.str()
|
||||
|
|
Loading…
Reference in a new issue