recopytex/backend/model/student.py

37 lines
922 B
Python
Raw Normal View History

2022-12-20 05:59:35 +00:00
from __future__ import annotations
from dataclasses import dataclass, field
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from backend.model.assessment import Assessment
2022-12-20 05:59:35 +00:00
@dataclass
class Tribe:
name: str
level: str
students: list[Student] = field(default_factory=list)
assessments: list[Assessment] = field(default_factory=list)
def register_assessment(self, assessment: Assessment) -> None:
self.assessments.append(assessment)
2022-12-20 05:59:35 +00:00
def register_student(self, student: Student) -> None:
2022-12-20 05:59:35 +00:00
self.students.append(student)
@dataclass
class Student:
def __init__(self, id: str, name: str, tribe: Tribe) -> None:
self.id = id
self.name = name
self.tribe = tribe
self.tribe.register_student(self)
def __eq__(self, other: object) -> bool:
if isinstance(other, Student):
return self.id == other.id
return False