Commit 5d7befde by Chris Rossi Committed by Diana Huang

Generate certificate URLs.

parent bb43d4ca
...@@ -4,6 +4,7 @@ LinkedIn profiles. ...@@ -4,6 +4,7 @@ LinkedIn profiles.
""" """
import json import json
import urllib
from courseware.courses import get_course_by_id from courseware.courses import get_course_by_id
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
...@@ -14,6 +15,8 @@ from optparse import make_option ...@@ -14,6 +15,8 @@ from optparse import make_option
from certificates.models import GeneratedCertificate from certificates.models import GeneratedCertificate
from ...models import LinkedIn from ...models import LinkedIn
from . import LinkedinAPI
class Command(BaseCommand): class Command(BaseCommand):
""" """
...@@ -58,6 +61,32 @@ class Command(BaseCommand): ...@@ -58,6 +61,32 @@ class Command(BaseCommand):
emailed.append(certificate.course_id) emailed.append(certificate.course_id)
account.emailed_courses = json.dumps(emailed) account.emailed_courses = json.dumps(emailed)
def certificate_url(api, course, certificate, grandfather=False):
"""
Generates a certificate URL based on LinkedIn's documentation. The
documentation is from a Word document: DAT_DOCUMENTATION_v3.12.docx
"""
tracking_code = '-'.join([
'eml',
'prof', # the 'product'--no idea what that's supposed to mean
course.org, # Partner's name
course.number, # Certificate's name
'gf' if grandfather else 'T'])
query = {
'pfCertificationName': certificate.name,
'pfAuthorityName': api.config['COMPANY_NAME'],
'pfAuthorityId': api.config['COMPANY_ID'],
'pfCertificationUrl': certificate.download_url,
'pfLicenseNo': certificate.course_id,
'pfCertStartDate': course.start.strftime('%Y%mI'),
'pfCertFuture': certificate.created_date.strftime('%Y%m'),
'_mSplash': '1',
'trk': tracking_code,
'startTask': 'CERTIFICATION_name',
'force': 'true',
}
return 'http://www.linkedin.com/profile/guided?' + urllib.urlencode(query)
def send_grandfather_email(user, certificates): def send_grandfather_email(user, certificates):
""" """
...@@ -72,10 +101,13 @@ def send_email(user, certificate): ...@@ -72,10 +101,13 @@ def send_email(user, certificate):
Email a user that recently earned a certificate, inviting them to post their Email a user that recently earned a certificate, inviting them to post their
certificate on their LinkedIn profile. certificate on their LinkedIn profile.
""" """
api = LinkedinAPI()
template = get_template("linkedin_email.html") template = get_template("linkedin_email.html")
course = get_course_by_id(certificate.course_id) course = get_course_by_id(certificate.course_id)
url = certificate_url(api, course, certificate)
context = Context({ context = Context({
'student_name': user.profile.name, 'student_name': user.profile.name,
'course_name': 'XXX', 'course_name': certificate.name,
'url': '#'}) 'url': url})
print template.render(context) print template.render(context)
print url
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
certificate to your profile. certificate to your profile.
{% endblocktrans %}</p> {% endblocktrans %}</p>
<p><a href="{{url}}"> <p><a href="{{url|safe}}">
<span>in<span> <span>in<span>
{% blocktrans %}Add to profile{% endblocktrans %} {% blocktrans %}Add to profile{% endblocktrans %}
</a></p> </a></p>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment