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
Show 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.
import
json
import
urllib
from
django.conf
import
settings
from
django.core.mail
import
send_mail
from
django.core.management.base
import
BaseCommand
from
django.template
import
Context
from
django.template.loader
import
get_template
from
django.core.urlresolvers
import
reverse
from
optparse
import
make_option
from
edxmako.shortcuts
import
render_to_string
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
.
import
LinkedInAPI
...
...
@@ -101,15 +105,31 @@ class Command(BaseCommand):
Send the 'grandfathered' email informing historical students that they
may now post their certificates on their LinkedIn profiles.
"""
template
=
get_template
(
"linkedin_grandfather_email.html"
)
links
=
[
{
'course_name'
:
certificate
.
name
,
'url'
:
self
.
certificate_url
(
certificate
,
grandfather
=
True
)}
for
certificate
in
certificates
]
context
=
Context
({
'student_name'
:
user
.
profile
.
name
,
'certificates'
:
links
})
body
=
template
.
render
(
context
)
courses_list
=
[]
for
cert
in
certificates
:
course
=
get_course_by_id
(
cert
.
course_id
)
course_url
=
'https://{}{}'
.
format
(
settings
.
SITE_NAME
,
reverse
(
'course_root'
,
kwargs
=
{
'course_id'
:
cert
.
course_id
})
)
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'
self
.
send_email
(
user
,
subject
,
body
)
...
...
lms/djangoapps/linkedin/management/commands/tests/test_mailusers.py
View file @
a3f1f660
...
...
@@ -7,36 +7,39 @@ import mock
from
certificates.models
import
GeneratedCertificate
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.utils.timezone
import
utc
from
django.test
import
TestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
from
student.models
import
UserProfile
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
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
):
"""
Test mail users command.
"""
def
setUp
(
self
):
courses
=
{
'TEST1'
:
mock
.
Mock
(
org
=
'TestX'
,
number
=
'1'
,
start
=
datetime
.
datetime
(
2010
,
5
,
12
,
2
,
42
,
tzinfo
=
utc
)),
'TEST2'
:
mock
.
Mock
(
org
=
'TestX'
,
number
=
'2'
),
'TEST3'
:
mock
.
Mock
(
org
=
'TestX'
,
number
=
'3'
),
}
def
get_course_by_id
(
id
):
return
courses
.
get
(
id
)
patcher
=
mock
.
patch
(
MODULE
+
'get_course_by_id'
,
get_course_by_id
)
patcher
.
start
()
self
.
addCleanup
(
patcher
.
stop
)
CourseFactory
.
create
(
org
=
'TESTX'
,
number
=
'1'
,
display_name
=
'TEST1'
,
start
=
datetime
.
datetime
(
2010
,
5
,
12
,
2
,
42
,
tzinfo
=
utc
),
end
=
datetime
.
datetime
(
2011
,
5
,
12
,
2
,
42
,
tzinfo
=
utc
))
CourseFactory
.
create
(
org
=
'TESTX'
,
number
=
'2'
,
display_name
=
'TEST2'
,
start
=
datetime
.
datetime
(
2010
,
5
,
12
,
2
,
42
,
tzinfo
=
utc
),
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
),
end
=
datetime
.
datetime
(
2011
,
5
,
12
,
2
,
42
,
tzinfo
=
utc
))
self
.
fred
=
fred
=
User
(
username
=
'fred'
,
email
=
'fred@bedrock.gov'
)
fred
.
save
()
...
...
@@ -51,19 +54,19 @@ class MailusersTests(TestCase):
self
.
cert1
=
cert1
=
GeneratedCertificate
(
status
=
'downloadable'
,
user
=
fred
,
course_id
=
'TEST1'
,
course_id
=
'TEST
X/1/TEST
1'
,
name
=
'TestX/Intro101'
,
download_url
=
'http://test.foo/test'
)
cert1
.
save
()
cert2
=
GeneratedCertificate
(
status
=
'downloadable'
,
user
=
fred
,
course_id
=
'TEST2'
)
course_id
=
'TEST
X/2/TEST
2'
)
cert2
.
save
()
cert3
=
GeneratedCertificate
(
status
=
'downloadable'
,
user
=
barney
,
course_id
=
'TEST3'
)
course_id
=
'TEST
X/3/TEST
3'
)
cert3
.
save
()
def
test_mail_users
(
self
):
...
...
@@ -73,9 +76,9 @@ class MailusersTests(TestCase):
fut
=
mailusers
.
Command
()
.
handle
fut
()
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
(
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
(
mail
.
outbox
[
0
]
.
from_email
,
'The Team <team@test.foo>'
)
self
.
assertEqual
(
...
...
@@ -94,7 +97,7 @@ class MailusersTests(TestCase):
fut
=
mailusers
.
Command
()
.
handle
fut
()
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
(
mail
.
outbox
[
0
]
.
to
,
[
'Barney Rubble <barney@bedrock.gov>'
])
...
...
@@ -106,9 +109,9 @@ class MailusersTests(TestCase):
fut
=
mailusers
.
Command
()
.
handle
fut
(
grandfather
=
True
)
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
(
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
(
mail
.
outbox
[
0
]
.
to
,
[
'Fred Flintstone <fred@bedrock.gov>'
])
...
...
@@ -120,15 +123,15 @@ class MailusersTests(TestCase):
Test emailing users, making sure they are only emailed about new
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
()
fut
=
mailusers
.
Command
()
.
handle
fut
()
fred
=
User
.
objects
.
get
(
username
=
'fred'
)
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
(
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
(
mail
.
outbox
[
0
]
.
to
,
[
'Fred Flintstone <fred@bedrock.gov>'
])
...
...
@@ -140,15 +143,15 @@ class MailusersTests(TestCase):
Test emailing users, making sure they are only emailed about new
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
()
fut
=
mailusers
.
Command
()
.
handle
fut
()
fred
=
User
.
objects
.
get
(
username
=
'fred'
)
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
(
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
(
mail
.
outbox
[
0
]
.
to
,
[
'Fred Flintstone <fred@bedrock.gov>'
])
...
...
@@ -165,6 +168,6 @@ class MailusersTests(TestCase):
'http://www.linkedin.com/profile/guided?'
'pfCertificationName=TestX
%2
FIntro101&pfAuthorityName=edX&'
'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&'
'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