|
|
@ -22,6 +22,7 @@ class Student:
|
|
|
|
self._validation_errors.append("姓名长度需在2-20个字符之间且为可打印字符")
|
|
|
|
self._validation_errors.append("姓名长度需在2-20个字符之间且为可打印字符")
|
|
|
|
if not self.name.isprintable():
|
|
|
|
if not self.name.isprintable():
|
|
|
|
self._validation_errors.append("姓名长度需在2-20个字符之间")
|
|
|
|
self._validation_errors.append("姓名长度需在2-20个字符之间")
|
|
|
|
|
|
|
|
|
|
|
|
def _validate_date(self) -> None:
|
|
|
|
def _validate_date(self) -> None:
|
|
|
|
today = date.today()
|
|
|
|
today = date.today()
|
|
|
|
if self.birth_date > today:
|
|
|
|
if self.birth_date > today:
|
|
|
@ -30,11 +31,14 @@ class Student:
|
|
|
|
self._validation_errors.append('入学日期不能在未来')
|
|
|
|
self._validation_errors.append('入学日期不能在未来')
|
|
|
|
if self.birth_date > self.enrollment_date:
|
|
|
|
if self.birth_date > self.enrollment_date:
|
|
|
|
self._validation_errors.append('入学日期不能早于出生日期')
|
|
|
|
self._validation_errors.append('入学日期不能早于出生日期')
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def is_valid(self) -> bool:
|
|
|
|
def is_valid(self) -> bool:
|
|
|
|
return len(self._validation_errors) == 0
|
|
|
|
return len(self._validation_errors) == 0
|
|
|
|
|
|
|
|
|
|
|
|
def get_errors(self) -> list[str]:
|
|
|
|
def get_errors(self) -> list[str]:
|
|
|
|
return self._validation_errors.copy()
|
|
|
|
return self._validation_errors.copy()
|
|
|
|
|
|
|
|
|
|
|
|
def __eq__(self, other) -> bool:
|
|
|
|
def __eq__(self, other) -> bool:
|
|
|
|
if not isinstance(other, Student):
|
|
|
|
if not isinstance(other, Student):
|
|
|
|
return NotImplemented
|
|
|
|
return NotImplemented
|
|
|
|