Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
77668afa
Commit
77668afa
authored
Jan 12, 2016
by
Bill DeRusha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update age calculation to be more conservative.
parent
fb9f8184
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
7 deletions
+23
-7
common/djangoapps/student/models.py
+14
-3
common/djangoapps/student/tests/test_create_account.py
+3
-2
common/djangoapps/student/tests/test_user_profile_properties.py
+6
-2
No files found.
common/djangoapps/student/models.py
View file @
77668afa
...
...
@@ -292,7 +292,7 @@ class UserProfile(models.Model):
year_of_birth
=
self
.
year_of_birth
year
=
datetime
.
now
(
UTC
)
.
year
if
year_of_birth
is
not
None
:
return
year
-
year_of_birth
return
self
.
_calculate_age
(
year
,
year_of_birth
)
@property
def
level_of_education_display
(
self
):
...
...
@@ -364,14 +364,25 @@ class UserProfile(models.Model):
if
date
is
None
:
age
=
self
.
age
else
:
age
=
date
.
year
-
year_of_birth
age
=
self
.
_calculate_age
(
date
.
year
,
year_of_birth
)
return
age
<
=
age_limit
return
age
<
age_limit
def
__enumerable_to_display
(
self
,
enumerables
,
enum_value
):
""" Get the human readable value from an enumerable list of key-value pairs. """
return
dict
(
enumerables
)[
enum_value
]
def
_calculate_age
(
self
,
year
,
year_of_birth
):
"""Calculate the youngest age for a user with a given year of birth.
:param year: year
:param year_of_birth: year of birth
:return: youngest age a user could be for the given year
"""
# There are legal implications regarding how we can contact users and what information we can make public
# based on their age, so we must take the most conservative estimate.
return
year
-
year_of_birth
-
1
@classmethod
def
country_cache_key_name
(
cls
,
user_id
):
"""Return cache key name to be used to cache current country.
...
...
common/djangoapps/student/tests/test_create_account.py
View file @
77668afa
...
...
@@ -118,6 +118,7 @@ class TestCreateAccount(TestCase):
@mock.patch
(
'student.views.analytics.identify'
)
def
test_segment_tracking
(
self
,
mock_segment_identify
,
_
):
year
=
datetime
.
now
()
.
year
year_of_birth
=
year
-
14
self
.
params
.
update
({
"level_of_education"
:
"a"
,
"gender"
:
"o"
,
...
...
@@ -125,7 +126,7 @@ class TestCreateAccount(TestCase):
"city"
:
"Exampleton"
,
"country"
:
"US"
,
"goals"
:
"To test this feature"
,
"year_of_birth"
:
str
(
year
),
"year_of_birth"
:
str
(
year
_of_birth
),
"extra1"
:
"extra_value1"
,
"extra2"
:
"extra_value2"
,
})
...
...
@@ -134,7 +135,7 @@ class TestCreateAccount(TestCase):
'email'
:
self
.
params
[
'email'
],
'username'
:
self
.
params
[
'username'
],
'name'
:
self
.
params
[
'name'
],
'age'
:
0
,
'age'
:
13
,
'education'
:
'Associate degree'
,
'address'
:
self
.
params
[
'mailing_address'
],
'gender'
:
'Other/Prefer Not to Say'
,
...
...
common/djangoapps/student/tests/test_user_profile_properties.py
View file @
77668afa
...
...
@@ -42,11 +42,15 @@ class UserProfilePropertiesTest(TestCase):
self
.
profile
.
save
()
@ddt.data
(
0
,
1
,
13
,
20
,
100
)
def
test_age
(
self
,
age
):
def
test_age
(
self
,
years_ago
):
"""Verify the age calculated correctly."""
current_year
=
datetime
.
datetime
.
now
()
.
year
self
.
_set_year_of_birth
(
current_year
-
age
)
self
.
_set_year_of_birth
(
current_year
-
years_ago
)
# In the year that your turn a certain age you will also have been a
# year younger than that in that same year. We calculate age based off of
# the youngest you could be that year.
age
=
years_ago
-
1
self
.
assertEqual
(
self
.
profile
.
age
,
age
)
def
test_age_no_birth_year
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment