Feat: add overwrite when 2 students have the same id and split tests

This commit is contained in:
2022-12-27 10:07:38 +01:00
parent e5a50e0be8
commit 9ec183c3a5
3 changed files with 53 additions and 21 deletions

View File

@@ -8,6 +8,10 @@ if TYPE_CHECKING:
from backend.model.student import Student
class TribeError(Exception):
pass
@dataclass
class Tribe:
name: str
@@ -18,7 +22,22 @@ class Tribe:
def register_assessment(self, assessment: Assessment) -> None:
self.assessments.append(assessment)
@property
def students_id(self) -> list[str]:
return [s.id for s in self.students]
def register_student(self, student: Student) -> None:
"""Register a student
If the student is already registered, it is modified.
"""
try:
old_student = next(filter(lambda s: s.id == student.id, self.students))
except StopIteration:
pass
else:
self.students.remove(old_student)
self.students.append(student)
def __eq__(self, other: object) -> bool: