1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-12-04 22:40:30 +00:00

Improve error messages

This commit is contained in:
Mo 2024-03-05 16:12:12 +01:00
parent 7d3717cb99
commit 293a73ede9

View file

@ -109,7 +109,7 @@ class PartStudent(db.Model):
def check(part, group): def check(part, group):
if group is not None and group.program != part.program: if group is not None and group.program != part.program:
raise DatabaseException( raise DatabaseException(
f"Group's program {group.program} and student part's program {part.program} do not match!" f"The group's program {group.program} and student part's program {part.program} don't match!"
) )
def __init__(self, part, group=None, **kwargs): def __init__(self, part, group=None, **kwargs):
@ -212,11 +212,13 @@ class Group(db.Model):
commonProgram = part_students[0].part.program commonProgram = part_students[0].part.program
if program and program != commonProgram: if program and program != commonProgram:
raise DatabaseException("Group's program and students' program mismatch!") raise DatabaseException(
f"The group's program and students' program don't match for the part students {part_students}!"
)
for partStudent in part_students[1:]: for partStudent in part_students[1:]:
if partStudent.part.program != commonProgram: if partStudent.part.program != commonProgram:
raise DatabaseException(f"Part Students {part_students} are not in the same program!") raise DatabaseException(f"The part students {part_students} are not in the same program!")
@staticmethod @staticmethod
def customInit(part_students): def customInit(part_students):
@ -461,7 +463,7 @@ class Appointment(db.Model):
assistant = semesterExperimentAssistants[0] assistant = semesterExperimentAssistants[0]
else: else:
raise DatabaseException( raise DatabaseException(
f"Experiment {semesterExperiment} has more than one assistant. You have to assign one of these assistants: {semesterExperimentAssistants}" f"The experiment {semesterExperiment} has more than one assistant. You have to assign one of these assistants: {semesterExperimentAssistants}"
) )
return assistant return assistant
@ -651,10 +653,12 @@ class ExperimentMark(db.Model):
@staticmethod @staticmethod
def check(part_student, group_experiment): def check(part_student, group_experiment):
if not part_student.group: if not part_student.group:
raise DatabaseException("The part student does not have a group yet!") raise DatabaseException(f"The part student {part_student} doesn't have a group yet!")
if group_experiment not in part_student.group.group_experiments: if group_experiment not in part_student.group.group_experiments:
raise DatabaseException("The group of the part student does not have the given group experiment!") raise DatabaseException(
f"The group {part_student.group} of the part student {part_student} doesn't have the given group experiment {group_experiment}!"
)
def __init__(self, part_student, group_experiment, **kwargs): def __init__(self, part_student, group_experiment, **kwargs):
ExperimentMark.check(part_student, group_experiment) ExperimentMark.check(part_student, group_experiment)