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
a3f1f660
Commit
a3f1f660
authored
Jan 09, 2014
by
Diana Huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Integrate new LinkedIn e-mail template
parent
a18bce81
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
67 deletions
+62
-67
lms/djangoapps/linkedin/management/commands/linkedin_mailusers.py
+30
-10
lms/djangoapps/linkedin/management/commands/tests/test_mailusers.py
+32
-29
lms/djangoapps/linkedin/templates/linkedin_grandfather_email.html
+0
-28
lms/templates/linkedin/linkedin_email.html
+0
-0
No files found.
lms/djangoapps/linkedin/management/commands/linkedin_mailusers.py
View file @
a3f1f660
...
@@ -6,14 +6,18 @@ LinkedIn profiles.
...
@@ -6,14 +6,18 @@ LinkedIn profiles.
import
json
import
json
import
urllib
import
urllib
from
django.conf
import
settings
from
django.core.mail
import
send_mail
from
django.core.mail
import
send_mail
from
django.core.management.base
import
BaseCommand
from
django.core.management.base
import
BaseCommand
from
django.template
import
Context
from
django.template
import
Context
from
django.template.loader
import
get_template
from
django.template.loader
import
get_template
from
django.core.urlresolvers
import
reverse
from
optparse
import
make_option
from
optparse
import
make_option
from
edxmako.shortcuts
import
render_to_string
from
certificates.models
import
GeneratedCertificate
from
certificates.models
import
GeneratedCertificate
from
courseware.courses
import
get_course_by_id
from
courseware.courses
import
get_course_by_id
,
course_image_url
from
...models
import
LinkedIn
from
...models
import
LinkedIn
from
.
import
LinkedInAPI
from
.
import
LinkedInAPI
...
@@ -101,15 +105,31 @@ class Command(BaseCommand):
...
@@ -101,15 +105,31 @@ class Command(BaseCommand):
Send the 'grandfathered' email informing historical students that they
Send the 'grandfathered' email informing historical students that they
may now post their certificates on their LinkedIn profiles.
may now post their certificates on their LinkedIn profiles.
"""
"""
template
=
get_template
(
"linkedin_grandfather_email.html"
)
courses_list
=
[]
links
=
[
for
cert
in
certificates
:
{
'course_name'
:
certificate
.
name
,
course
=
get_course_by_id
(
cert
.
course_id
)
'url'
:
self
.
certificate_url
(
certificate
,
grandfather
=
True
)}
course_url
=
'https://{}{}'
.
format
(
for
certificate
in
certificates
]
settings
.
SITE_NAME
,
context
=
Context
({
reverse
(
'course_root'
,
kwargs
=
{
'course_id'
:
cert
.
course_id
})
'student_name'
:
user
.
profile
.
name
,
)
'certificates'
:
links
})
body
=
template
.
render
(
context
)
course_title
=
course
.
display_name
course_img_url
=
'https://{}{}'
.
format
(
settings
.
SITE_NAME
,
course_image_url
(
course
))
course_end_date
=
course
.
end
.
strftime
(
'
%
b
%
Y'
)
course_org
=
course
.
display_organization
courses_list
.
append
({
'course_url'
:
course_url
,
'course_org'
:
course_org
,
'course_title'
:
course_title
,
'course_image_url'
:
course_img_url
,
'course_end_date'
:
course_end_date
,
'linkedin_add_url'
:
self
.
certificate_url
(
cert
),
})
context
=
{
'courses_list'
:
courses_list
,
'num_courses'
:
len
(
courses_list
)}
body
=
render_to_string
(
'linkedin/linkedin_email.html'
,
context
)
subject
=
'Congratulations! Put your certificates on LinkedIn'
subject
=
'Congratulations! Put your certificates on LinkedIn'
self
.
send_email
(
user
,
subject
,
body
)
self
.
send_email
(
user
,
subject
,
body
)
...
...
lms/djangoapps/linkedin/management/commands/tests/test_mailusers.py
View file @
a3f1f660
...
@@ -7,36 +7,39 @@ import mock
...
@@ -7,36 +7,39 @@ import mock
from
certificates.models
import
GeneratedCertificate
from
certificates.models
import
GeneratedCertificate
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.conf
import
settings
from
django.test.utils
import
override_settings
from
django.core
import
mail
from
django.core
import
mail
from
django.utils.timezone
import
utc
from
django.utils.timezone
import
utc
from
django.test
import
TestCase
from
django.test
import
TestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
from
student.models
import
UserProfile
from
student.models
import
UserProfile
from
linkedin.models
import
LinkedIn
from
linkedin.models
import
LinkedIn
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
,
mixed_store_config
from
linkedin.management.commands
import
linkedin_mailusers
as
mailusers
from
linkedin.management.commands
import
linkedin_mailusers
as
mailusers
MODULE
=
'linkedin.management.commands.linkedin_mailusers.'
MODULE
=
'linkedin.management.commands.linkedin_mailusers.'
TEST_DATA_MIXED_MODULESTORE
=
mixed_store_config
(
settings
.
COMMON_TEST_DATA_ROOT
,
{})
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
class
MailusersTests
(
TestCase
):
class
MailusersTests
(
TestCase
):
"""
"""
Test mail users command.
Test mail users command.
"""
"""
def
setUp
(
self
):
def
setUp
(
self
):
courses
=
{
CourseFactory
.
create
(
org
=
'TESTX'
,
number
=
'1'
,
display_name
=
'TEST1'
,
'TEST1'
:
mock
.
Mock
(
start
=
datetime
.
datetime
(
2010
,
5
,
12
,
2
,
42
,
tzinfo
=
utc
),
org
=
'TestX'
,
number
=
'1'
,
end
=
datetime
.
datetime
(
2011
,
5
,
12
,
2
,
42
,
tzinfo
=
utc
))
start
=
datetime
.
datetime
(
2010
,
5
,
12
,
2
,
42
,
tzinfo
=
utc
)),
CourseFactory
.
create
(
org
=
'TESTX'
,
number
=
'2'
,
display_name
=
'TEST2'
,
'TEST2'
:
mock
.
Mock
(
org
=
'TestX'
,
number
=
'2'
),
start
=
datetime
.
datetime
(
2010
,
5
,
12
,
2
,
42
,
tzinfo
=
utc
),
'TEST3'
:
mock
.
Mock
(
org
=
'TestX'
,
number
=
'3'
),
end
=
datetime
.
datetime
(
2011
,
5
,
12
,
2
,
42
,
tzinfo
=
utc
))
}
CourseFactory
.
create
(
org
=
'TESTX'
,
number
=
'3'
,
display_name
=
'TEST3'
,
start
=
datetime
.
datetime
(
2010
,
5
,
12
,
2
,
42
,
tzinfo
=
utc
),
def
get_course_by_id
(
id
):
end
=
datetime
.
datetime
(
2011
,
5
,
12
,
2
,
42
,
tzinfo
=
utc
))
return
courses
.
get
(
id
)
patcher
=
mock
.
patch
(
MODULE
+
'get_course_by_id'
,
get_course_by_id
)
patcher
.
start
()
self
.
addCleanup
(
patcher
.
stop
)
self
.
fred
=
fred
=
User
(
username
=
'fred'
,
email
=
'fred@bedrock.gov'
)
self
.
fred
=
fred
=
User
(
username
=
'fred'
,
email
=
'fred@bedrock.gov'
)
fred
.
save
()
fred
.
save
()
...
@@ -51,19 +54,19 @@ class MailusersTests(TestCase):
...
@@ -51,19 +54,19 @@ class MailusersTests(TestCase):
self
.
cert1
=
cert1
=
GeneratedCertificate
(
self
.
cert1
=
cert1
=
GeneratedCertificate
(
status
=
'downloadable'
,
status
=
'downloadable'
,
user
=
fred
,
user
=
fred
,
course_id
=
'TEST1'
,
course_id
=
'TEST
X/1/TEST
1'
,
name
=
'TestX/Intro101'
,
name
=
'TestX/Intro101'
,
download_url
=
'http://test.foo/test'
)
download_url
=
'http://test.foo/test'
)
cert1
.
save
()
cert1
.
save
()
cert2
=
GeneratedCertificate
(
cert2
=
GeneratedCertificate
(
status
=
'downloadable'
,
status
=
'downloadable'
,
user
=
fred
,
user
=
fred
,
course_id
=
'TEST2'
)
course_id
=
'TEST
X/2/TEST
2'
)
cert2
.
save
()
cert2
.
save
()
cert3
=
GeneratedCertificate
(
cert3
=
GeneratedCertificate
(
status
=
'downloadable'
,
status
=
'downloadable'
,
user
=
barney
,
user
=
barney
,
course_id
=
'TEST3'
)
course_id
=
'TEST
X/3/TEST
3'
)
cert3
.
save
()
cert3
.
save
()
def
test_mail_users
(
self
):
def
test_mail_users
(
self
):
...
@@ -73,9 +76,9 @@ class MailusersTests(TestCase):
...
@@ -73,9 +76,9 @@ class MailusersTests(TestCase):
fut
=
mailusers
.
Command
()
.
handle
fut
=
mailusers
.
Command
()
.
handle
fut
()
fut
()
self
.
assertEqual
(
self
.
assertEqual
(
json
.
loads
(
self
.
fred
.
linkedin
.
emailed_courses
),
[
'TEST
1'
,
'
TEST2'
])
json
.
loads
(
self
.
fred
.
linkedin
.
emailed_courses
),
[
'TEST
X/1/TEST1'
,
'TESTX/2/
TEST2'
])
self
.
assertEqual
(
self
.
assertEqual
(
json
.
loads
(
self
.
barney
.
linkedin
.
emailed_courses
),
[
'TEST3'
])
json
.
loads
(
self
.
barney
.
linkedin
.
emailed_courses
),
[
'TEST
X/3/TEST
3'
])
self
.
assertEqual
(
len
(
mail
.
outbox
),
3
)
self
.
assertEqual
(
len
(
mail
.
outbox
),
3
)
self
.
assertEqual
(
mail
.
outbox
[
0
]
.
from_email
,
'The Team <team@test.foo>'
)
self
.
assertEqual
(
mail
.
outbox
[
0
]
.
from_email
,
'The Team <team@test.foo>'
)
self
.
assertEqual
(
self
.
assertEqual
(
...
@@ -94,7 +97,7 @@ class MailusersTests(TestCase):
...
@@ -94,7 +97,7 @@ class MailusersTests(TestCase):
fut
=
mailusers
.
Command
()
.
handle
fut
=
mailusers
.
Command
()
.
handle
fut
()
fut
()
self
.
assertEqual
(
self
.
assertEqual
(
json
.
loads
(
self
.
barney
.
linkedin
.
emailed_courses
),
[
'TEST3'
])
json
.
loads
(
self
.
barney
.
linkedin
.
emailed_courses
),
[
'TEST
X/3/TEST
3'
])
self
.
assertEqual
(
len
(
mail
.
outbox
),
1
)
self
.
assertEqual
(
len
(
mail
.
outbox
),
1
)
self
.
assertEqual
(
self
.
assertEqual
(
mail
.
outbox
[
0
]
.
to
,
[
'Barney Rubble <barney@bedrock.gov>'
])
mail
.
outbox
[
0
]
.
to
,
[
'Barney Rubble <barney@bedrock.gov>'
])
...
@@ -106,9 +109,9 @@ class MailusersTests(TestCase):
...
@@ -106,9 +109,9 @@ class MailusersTests(TestCase):
fut
=
mailusers
.
Command
()
.
handle
fut
=
mailusers
.
Command
()
.
handle
fut
(
grandfather
=
True
)
fut
(
grandfather
=
True
)
self
.
assertEqual
(
self
.
assertEqual
(
json
.
loads
(
self
.
fred
.
linkedin
.
emailed_courses
),
[
'TEST
1'
,
'
TEST2'
])
json
.
loads
(
self
.
fred
.
linkedin
.
emailed_courses
),
[
'TEST
X/1/TEST1'
,
'TESTX/2/
TEST2'
])
self
.
assertEqual
(
self
.
assertEqual
(
json
.
loads
(
self
.
barney
.
linkedin
.
emailed_courses
),
[
'TEST3'
])
json
.
loads
(
self
.
barney
.
linkedin
.
emailed_courses
),
[
'TEST
X/3/TEST
3'
])
self
.
assertEqual
(
len
(
mail
.
outbox
),
2
)
self
.
assertEqual
(
len
(
mail
.
outbox
),
2
)
self
.
assertEqual
(
self
.
assertEqual
(
mail
.
outbox
[
0
]
.
to
,
[
'Fred Flintstone <fred@bedrock.gov>'
])
mail
.
outbox
[
0
]
.
to
,
[
'Fred Flintstone <fred@bedrock.gov>'
])
...
@@ -120,15 +123,15 @@ class MailusersTests(TestCase):
...
@@ -120,15 +123,15 @@ class MailusersTests(TestCase):
Test emailing users, making sure they are only emailed about new
Test emailing users, making sure they are only emailed about new
certificates.
certificates.
"""
"""
self
.
fred
.
linkedin
.
emailed_courses
=
json
.
dumps
([
'TEST1'
])
self
.
fred
.
linkedin
.
emailed_courses
=
json
.
dumps
([
'TEST
X/1/TEST
1'
])
self
.
fred
.
linkedin
.
save
()
self
.
fred
.
linkedin
.
save
()
fut
=
mailusers
.
Command
()
.
handle
fut
=
mailusers
.
Command
()
.
handle
fut
()
fut
()
fred
=
User
.
objects
.
get
(
username
=
'fred'
)
fred
=
User
.
objects
.
get
(
username
=
'fred'
)
self
.
assertEqual
(
self
.
assertEqual
(
json
.
loads
(
fred
.
linkedin
.
emailed_courses
),
[
'TEST
1'
,
'
TEST2'
])
json
.
loads
(
fred
.
linkedin
.
emailed_courses
),
[
'TEST
X/1/TEST1'
,
'TESTX/2/
TEST2'
])
self
.
assertEqual
(
self
.
assertEqual
(
json
.
loads
(
self
.
barney
.
linkedin
.
emailed_courses
),
[
'TEST3'
])
json
.
loads
(
self
.
barney
.
linkedin
.
emailed_courses
),
[
'TEST
X/3/TEST
3'
])
self
.
assertEqual
(
len
(
mail
.
outbox
),
2
)
self
.
assertEqual
(
len
(
mail
.
outbox
),
2
)
self
.
assertEqual
(
self
.
assertEqual
(
mail
.
outbox
[
0
]
.
to
,
[
'Fred Flintstone <fred@bedrock.gov>'
])
mail
.
outbox
[
0
]
.
to
,
[
'Fred Flintstone <fred@bedrock.gov>'
])
...
@@ -140,15 +143,15 @@ class MailusersTests(TestCase):
...
@@ -140,15 +143,15 @@ class MailusersTests(TestCase):
Test emailing users, making sure they are only emailed about new
Test emailing users, making sure they are only emailed about new
certificates.
certificates.
"""
"""
self
.
barney
.
linkedin
.
emailed_courses
=
json
.
dumps
([
'TEST3'
])
self
.
barney
.
linkedin
.
emailed_courses
=
json
.
dumps
([
'TEST
X/3/TEST
3'
])
self
.
barney
.
linkedin
.
save
()
self
.
barney
.
linkedin
.
save
()
fut
=
mailusers
.
Command
()
.
handle
fut
=
mailusers
.
Command
()
.
handle
fut
()
fut
()
fred
=
User
.
objects
.
get
(
username
=
'fred'
)
fred
=
User
.
objects
.
get
(
username
=
'fred'
)
self
.
assertEqual
(
self
.
assertEqual
(
json
.
loads
(
fred
.
linkedin
.
emailed_courses
),
[
'TEST
1'
,
'
TEST2'
])
json
.
loads
(
fred
.
linkedin
.
emailed_courses
),
[
'TEST
X/1/TEST1'
,
'TESTX/2/
TEST2'
])
self
.
assertEqual
(
self
.
assertEqual
(
json
.
loads
(
self
.
barney
.
linkedin
.
emailed_courses
),
[
'TEST3'
])
json
.
loads
(
self
.
barney
.
linkedin
.
emailed_courses
),
[
'TEST
X/3/TEST
3'
])
self
.
assertEqual
(
len
(
mail
.
outbox
),
2
)
self
.
assertEqual
(
len
(
mail
.
outbox
),
2
)
self
.
assertEqual
(
self
.
assertEqual
(
mail
.
outbox
[
0
]
.
to
,
[
'Fred Flintstone <fred@bedrock.gov>'
])
mail
.
outbox
[
0
]
.
to
,
[
'Fred Flintstone <fred@bedrock.gov>'
])
...
@@ -165,6 +168,6 @@ class MailusersTests(TestCase):
...
@@ -165,6 +168,6 @@ class MailusersTests(TestCase):
'http://www.linkedin.com/profile/guided?'
'http://www.linkedin.com/profile/guided?'
'pfCertificationName=TestX
%2
FIntro101&pfAuthorityName=edX&'
'pfCertificationName=TestX
%2
FIntro101&pfAuthorityName=edX&'
'pfAuthorityId=0000000&'
'pfAuthorityId=0000000&'
'pfCertificationUrl=http
%3
A
%2
F
%2
Ftest.foo
%2
Ftest&pfLicenseNo=TEST1&'
'pfCertificationUrl=http
%3
A
%2
F
%2
Ftest.foo
%2
Ftest&pfLicenseNo=TEST
X
%2
F1
%2
FTEST
1&'
'pfCertStartDate=201005&_mSplash=1&'
'pfCertStartDate=201005&_mSplash=1&'
'trk=eml-prof-T
est
X-1-T&startTask=CERTIFICATION_NAME&force=true'
)
'trk=eml-prof-T
EST
X-1-T&startTask=CERTIFICATION_NAME&force=true'
)
lms/djangoapps/linkedin/templates/linkedin_grandfather_email.html
deleted
100644 → 0
View file @
a18bce81
{% load i18n %}
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
>
<meta
name=
"viewport"
content=
"initial-scale=1.0"
>
</head>
<body>
<p>
{% blocktrans with name=student_name %}
Dear {{student_name}},
{% endblocktrans %}
</p>
<p>
{% blocktrans with name=course_name %}
We've partnered with LinkedIn and now you can put your certificates on
your LinkedIn profile. Just use the links below.
{% endblocktrans %}
</p>
{% for cert in certificates %}
<p>
<b>
{{cert.course_name}}
</b>
:
<a
href=
"{{cert.url|safe}}"
>
<span>
in
<span>
{% blocktrans %}Add to profile{% endblocktrans %}
</a>
</p>
{% endfor %}
</body>
</html>
lms/templates/linkedin/linkedin_email.html
0 → 100644
View file @
a3f1f660
This diff is collapsed.
Click to expand it.
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