2022-12-20 05:59:35 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2022-12-27 07:00:28 +00:00
|
|
|
from dataclasses import dataclass, field
|
|
|
|
from datetime import datetime
|
2022-12-26 10:46:29 +00:00
|
|
|
from typing import TYPE_CHECKING, Optional
|
2022-12-27 07:00:28 +00:00
|
|
|
from uuid import UUID, uuid4
|
2022-12-20 07:23:52 +00:00
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
2022-12-20 07:28:45 +00:00
|
|
|
from backend.model.tribe import Tribe
|
2022-12-20 05:59:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class Student:
|
2022-12-21 06:24:48 +00:00
|
|
|
name: str
|
|
|
|
tribe: Tribe
|
2022-12-27 07:00:28 +00:00
|
|
|
id: str = field(default_factory=lambda: str(uuid4()))
|
2022-12-20 05:59:35 +00:00
|
|
|
|
2022-12-21 06:24:48 +00:00
|
|
|
def __post_init__(self) -> None:
|
2022-12-20 05:59:35 +00:00
|
|
|
self.tribe.register_student(self)
|
|
|
|
|
|
|
|
def __eq__(self, other: object) -> bool:
|
|
|
|
if isinstance(other, Student):
|
|
|
|
return self.id == other.id
|
|
|
|
return False
|
2022-12-26 10:21:05 +00:00
|
|
|
|
|
|
|
def __hash__(self) -> int:
|
|
|
|
return hash(self.id)
|
2022-12-27 07:00:28 +00:00
|
|
|
|
|
|
|
def to_tuple(self) -> tuple:
|
|
|
|
return (self.id, self.name, self.tribe.name)
|
|
|
|
|
2022-12-27 10:57:50 +00:00
|
|
|
def to_dict(self, full_tribe=False) -> dict:
|
2022-12-27 07:00:28 +00:00
|
|
|
return {"id": self.id, "name": self.name, "tribe_name": self.tribe.name}
|