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
28e3b1cb
Commit
28e3b1cb
authored
Jan 11, 2017
by
Simon Chen
Committed by
GitHub
Jan 11, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14297 from edx/schen/ECOM-6760
Add the Sailthru welcome email delay
parents
ec9560af
8309930b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
3 deletions
+43
-3
lms/djangoapps/email_marketing/migrations/0004_emailmarketingconfiguration_welcome_email_send_delay.py
+19
-0
lms/djangoapps/email_marketing/models.py
+10
-0
lms/djangoapps/email_marketing/tasks.py
+10
-3
lms/djangoapps/email_marketing/tests/test_signals.py
+4
-0
No files found.
lms/djangoapps/email_marketing/migrations/0004_emailmarketingconfiguration_welcome_email_send_delay.py
0 → 100644
View file @
28e3b1cb
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'email_marketing'
,
'0003_auto_20160715_1145'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'emailmarketingconfiguration'
,
name
=
'welcome_email_send_delay'
,
field
=
models
.
IntegerField
(
default
=
600
,
help_text
=
'Number of seconds to delay the sending of User Welcome email after user has been activated'
),
),
]
lms/djangoapps/email_marketing/models.py
View file @
28e3b1cb
...
...
@@ -127,6 +127,16 @@ class EmailMarketingConfiguration(ConfigurationModel):
)
)
# The number of seconds to delay for welcome emails sending. This is needed to acommendate those
# learners who created user account during course enrollment so we can send a different message
# in our welcome email.
welcome_email_send_delay
=
models
.
fields
.
IntegerField
(
default
=
600
,
help_text
=
_
(
"Number of seconds to delay the sending of User Welcome email after user has been activated"
)
)
def
__unicode__
(
self
):
return
u"Email marketing configuration: New user list
%
s, Activation template:
%
s"
%
\
(
self
.
sailthru_new_user_list
,
self
.
sailthru_activation_template
)
lms/djangoapps/email_marketing/tasks.py
View file @
28e3b1cb
...
...
@@ -3,6 +3,7 @@ This file contains celery tasks for email marketing signal handler.
"""
import
logging
import
time
from
datetime
import
datetime
,
timedelta
from
celery
import
task
from
django.core.cache
import
cache
...
...
@@ -56,10 +57,16 @@ def update_user(self, sailthru_vars, email, site=None, new_user=False, activatio
# if activating user, send welcome email
if
activation
and
email_config
.
sailthru_activation_template
:
scheduled_datetime
=
datetime
.
utcnow
()
+
timedelta
(
seconds
=
email_config
.
welcome_email_send_delay
)
try
:
sailthru_response
=
sailthru_client
.
api_post
(
"send"
,
{
"email"
:
email
,
"template"
:
email_config
.
sailthru_activation_template
})
sailthru_response
=
sailthru_client
.
api_post
(
"send"
,
{
"email"
:
email
,
"template"
:
email_config
.
sailthru_activation_template
,
"schedule_time"
:
scheduled_datetime
.
strftime
(
'
%
Y-
%
m-
%
dT
%
H:
%
M:
%
SZ'
)
}
)
except
SailthruClientError
as
exc
:
log
.
error
(
"Exception attempting to send welcome email to user
%
s in Sailthru -
%
s"
,
email
,
unicode
(
exc
))
raise
self
.
retry
(
exc
=
exc
,
...
...
lms/djangoapps/email_marketing/tests/test_signals.py
View file @
28e3b1cb
"""Tests of email marketing signal handlers."""
import
ddt
import
logging
import
datetime
from
django.test
import
TestCase
from
django.contrib.auth.models
import
AnonymousUser
...
...
@@ -45,6 +46,7 @@ def update_email_marketing_config(enabled=True, key='badkey', secret='badsecret'
sailthru_get_tags_from_sailthru
=
False
,
sailthru_enroll_cost
=
enroll_cost
,
sailthru_max_retries
=
0
,
welcome_email_send_delay
=
600
)
...
...
@@ -168,12 +170,14 @@ class EmailMarketingTests(TestCase):
"""
mock_sailthru_post
.
return_value
=
SailthruResponse
(
JsonResponse
({
'ok'
:
True
}))
mock_sailthru_get
.
return_value
=
SailthruResponse
(
JsonResponse
({
'lists'
:
[{
'name'
:
'new list'
}],
'ok'
:
True
}))
expected_schedule
=
datetime
.
datetime
.
utcnow
()
+
datetime
.
timedelta
(
seconds
=
600
)
update_user
.
delay
({},
self
.
user
.
email
,
new_user
=
True
,
activation
=
True
)
# look for call args for 2nd call
self
.
assertEquals
(
mock_sailthru_post
.
call_args
[
0
][
0
],
"send"
)
userparms
=
mock_sailthru_post
.
call_args
[
0
][
1
]
self
.
assertEquals
(
userparms
[
'email'
],
TEST_EMAIL
)
self
.
assertEquals
(
userparms
[
'template'
],
"Activation"
)
self
.
assertEquals
(
userparms
[
'schedule_time'
],
expected_schedule
.
strftime
(
'
%
Y-
%
m-
%
dT
%
H:
%
M:
%
SZ'
))
@patch
(
'email_marketing.tasks.log.error'
)
@patch
(
'email_marketing.tasks.SailthruClient.api_post'
)
...
...
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