mirror of
https://github.com/ae-utbm/sith.git
synced 2026-10-02 17:04:19 +00:00
resolved crash when user has no birthdate
This commit is contained in:
1 parent
d3c115e3f9
commit
6c276dc596
1 file changed
+3
@@ -470,7 +470,10 @@ class User(AbstractBaseUser):
|
|||||||
def age(self) -> int:
|
def age(self) -> int:
|
||||||
"""
|
"""
|
||||||
Return the age this user has the day the method is called.
|
Return the age this user has the day the method is called.
|
||||||
|
If the user has not filled his age, return 0
|
||||||
"""
|
"""
|
||||||
|
if self.date_of_birth is None:
|
||||||
|
return 0
|
||||||
today = timezone.now()
|
today = timezone.now()
|
||||||
age = today.year - self.date_of_birth.year
|
age = today.year - self.date_of_birth.year
|
||||||
# remove a year if this year's birthday is yet to come
|
# remove a year if this year's birthday is yet to come
|
||||||
|
|||||||
Reference in new issue
Block a user