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
d75a36a3
Commit
d75a36a3
authored
Sep 23, 2015
by
Bill DeRusha
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9853 from edx/bderusha/mailchimp-sync
Add mailchimp list fields and config for new users
parents
d8d49f75
ccc43cfe
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
134 additions
and
6 deletions
+134
-6
common/djangoapps/student/models.py
+30
-2
common/djangoapps/student/tests/test_user_profile_properties.py
+79
-0
common/djangoapps/student/views.py
+22
-4
lms/envs/aws.py
+3
-0
No files found.
common/djangoapps/student/models.py
View file @
d75a36a3
...
...
@@ -282,6 +282,26 @@ class UserProfile(models.Model):
"""
return
self
.
profile_image_uploaded_at
is
not
None
@property
def
age
(
self
):
""" Convenience method that returns the age given a year_of_birth. """
year_of_birth
=
self
.
year_of_birth
year
=
datetime
.
now
(
UTC
)
.
year
if
year_of_birth
is
not
None
:
return
year
-
year_of_birth
@property
def
level_of_education_display
(
self
):
""" Convenience method that returns the human readable level of education. """
if
self
.
level_of_education
:
return
self
.
__enumerable_to_display
(
self
.
LEVEL_OF_EDUCATION_CHOICES
,
self
.
level_of_education
)
@property
def
gender_display
(
self
):
""" Convenience method that returns the human readable gender. """
if
self
.
gender
:
return
self
.
__enumerable_to_display
(
self
.
GENDER_CHOICES
,
self
.
gender
)
def
get_meta
(
self
):
# pylint: disable=missing-docstring
js_str
=
self
.
meta
if
not
js_str
:
...
...
@@ -336,9 +356,17 @@ class UserProfile(models.Model):
year_of_birth
=
self
.
year_of_birth
if
year_of_birth
is
None
:
return
default_requires_consent
if
date
is
None
:
date
=
datetime
.
now
(
UTC
)
return
date
.
year
-
year_of_birth
<=
age_limit
age
=
self
.
age
else
:
age
=
date
.
year
-
year_of_birth
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
]
@receiver
(
pre_save
,
sender
=
UserProfile
)
...
...
common/djangoapps/student/tests/test_user_profile_properties.py
0 → 100644
View file @
d75a36a3
"""Unit tests for custom UserProfile properties."""
import
datetime
import
ddt
from
django.test
import
TestCase
from
student.models
import
UserProfile
from
student.tests.factories
import
UserFactory
@ddt.ddt
class
UserProfilePropertiesTest
(
TestCase
):
"""Unit tests for age, gender_display, and level_of_education_display properties ."""
password
=
"test"
def
setUp
(
self
):
super
(
UserProfilePropertiesTest
,
self
)
.
setUp
()
self
.
user
=
UserFactory
.
create
(
password
=
self
.
password
)
self
.
profile
=
self
.
user
.
profile
def
_set_year_of_birth
(
self
,
year_of_birth
):
"""
Helper method that sets a birth year for the specified user.
"""
self
.
profile
.
year_of_birth
=
year_of_birth
self
.
profile
.
save
()
def
_set_level_of_education
(
self
,
level_of_education
):
"""
Helper method that sets a level of education for the specified user.
"""
self
.
profile
.
level_of_education
=
level_of_education
self
.
profile
.
save
()
def
_set_gender
(
self
,
gender
):
"""
Helper method that sets a gender for the specified user.
"""
self
.
profile
.
gender
=
gender
self
.
profile
.
save
()
@ddt.data
(
0
,
1
,
13
,
20
,
100
)
def
test_age
(
self
,
age
):
"""Verify the age calculated correctly."""
current_year
=
datetime
.
datetime
.
now
()
.
year
self
.
_set_year_of_birth
(
current_year
-
age
)
self
.
assertEqual
(
self
.
profile
.
age
,
age
)
def
test_age_no_birth_year
(
self
):
"""Verify nothing is returned."""
self
.
assertIsNone
(
self
.
profile
.
age
)
@ddt.data
(
*
UserProfile
.
LEVEL_OF_EDUCATION_CHOICES
)
@ddt.unpack
def
test_display_level_of_education
(
self
,
level_enum
,
display_level
):
"""Verify the level of education is displayed correctly."""
self
.
_set_level_of_education
(
level_enum
)
self
.
assertEqual
(
self
.
profile
.
level_of_education_display
,
display_level
)
def
test_display_level_of_education_none_set
(
self
):
"""Verify nothing is returned."""
self
.
assertIsNone
(
self
.
profile
.
level_of_education_display
)
@ddt.data
(
*
UserProfile
.
GENDER_CHOICES
)
@ddt.unpack
def
test_display_gender
(
self
,
gender_enum
,
display_gender
):
"""Verify the gender displayed correctly."""
self
.
_set_gender
(
gender_enum
)
self
.
assertEqual
(
self
.
profile
.
gender_display
,
display_gender
)
def
test_display_gender_none_set
(
self
):
"""Verify nothing is returned."""
self
.
_set_gender
(
None
)
self
.
assertIsNone
(
self
.
profile
.
gender_display
)
common/djangoapps/student/views.py
View file @
d75a36a3
...
...
@@ -1603,10 +1603,28 @@ def create_account_with_params(request, params):
# Track the user's registration
if
settings
.
FEATURES
.
get
(
'SEGMENT_IO_LMS'
)
and
hasattr
(
settings
,
'SEGMENT_IO_LMS_KEY'
):
tracking_context
=
tracker
.
get_tracker
()
.
resolve_context
()
analytics
.
identify
(
user
.
id
,
{
'email'
:
user
.
email
,
'username'
:
user
.
username
,
})
identity_args
=
[
user
.
id
,
# pylint: disable=no-member
{
'email'
:
user
.
email
,
'username'
:
user
.
username
,
'name'
:
profile
.
name
,
'age'
:
profile
.
age
,
'education'
:
profile
.
level_of_education_display
,
'address'
:
profile
.
mailing_address
,
'gender'
:
profile
.
gender_display
,
'country'
:
profile
.
country
,
}
]
if
hasattr
(
settings
,
'MAILCHIMP_NEW_USER_LIST_ID'
):
identity_args
.
append
({
"MailChimp"
:
{
"listId"
:
settings
.
MAILCHIMP_NEW_USER_LIST_ID
}
})
analytics
.
identify
(
*
identity_args
)
analytics
.
track
(
user
.
id
,
...
...
lms/envs/aws.py
View file @
d75a36a3
...
...
@@ -470,6 +470,9 @@ ANALYTICS_DATA_TOKEN = AUTH_TOKENS.get("ANALYTICS_DATA_TOKEN", ANALYTICS_DATA_TO
ANALYTICS_DASHBOARD_URL
=
ENV_TOKENS
.
get
(
"ANALYTICS_DASHBOARD_URL"
,
ANALYTICS_DASHBOARD_URL
)
ANALYTICS_DASHBOARD_NAME
=
ENV_TOKENS
.
get
(
"ANALYTICS_DASHBOARD_NAME"
,
PLATFORM_NAME
+
" Insights"
)
# Mailchimp New User List
MAILCHIMP_NEW_USER_LIST_ID
=
ENV_TOKENS
.
get
(
"MAILCHIMP_NEW_USER_LIST_ID"
)
# Zendesk
ZENDESK_USER
=
AUTH_TOKENS
.
get
(
"ZENDESK_USER"
)
ZENDESK_API_KEY
=
AUTH_TOKENS
.
get
(
"ZENDESK_API_KEY"
)
...
...
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