Commit 57ef60de by Awais

ECOM-1028 adding linked-in button , config model and migration for linked url.

ECOM-1028 update the migration and move the code into class method.
parent e43f1a8b
......@@ -5,7 +5,9 @@ from django import forms
from config_models.admin import ConfigurationModelAdmin
from student.models import UserProfile, UserTestGroup, CourseEnrollmentAllowed, DashboardConfiguration
from student.models import CourseEnrollment, Registration, PendingNameChange, CourseAccessRole
from student.models import (
CourseEnrollment, Registration, PendingNameChange, CourseAccessRole, LinkedInAddToProfileConfiguration
)
from ratelimitbackend import admin
from student.roles import REGISTERED_ACCESS_ROLES
......@@ -42,3 +44,5 @@ admin.site.register(PendingNameChange)
admin.site.register(CourseAccessRole, CourseAccessRoleAdmin)
admin.site.register(DashboardConfiguration, ConfigurationModelAdmin)
admin.site.register(LinkedInAddToProfileConfiguration)
......@@ -20,7 +20,9 @@ from collections import defaultdict
import dogstats_wrapper as dog_stats_api
from django.db.models import Q
import pytz
from urllib import urlencode
from django.utils.translation import ugettext_lazy
from django.conf import settings
from django.utils import timezone
from django.contrib.auth.models import User
......@@ -1435,3 +1437,33 @@ class DashboardConfiguration(ConfigurationModel):
@property
def recent_enrollment_seconds(self):
return self.recent_enrollment_time_delta
class LinkedInAddToProfileConfiguration(ConfigurationModel):
"""
LinkedIn Add to Profile Configuration
"""
# tracking code field
dashboard_tracking_code = models.TextField(
blank=True,
help_text=ugettext_lazy(
u"A dashboard tracking code field for LinkedIn Add-to-profile Certificates. "
u"e.g 0_0dPSPyS070e0HsE9HNz_13_d11_"
)
)
@classmethod
def linked_in_dashboard_tracking_code_url(cls, params):
"""
Get the linked-in Configuration.
"""
config = cls.current()
if config.enabled:
return u'http://www.linkedin.com/profile/add?_ed={tracking_code}&{params}'.format(
tracking_code=config.dashboard_tracking_code,
params=urlencode(params)
)
return None
def __unicode__(self):
return self.dashboard_tracking_code
......@@ -54,7 +54,7 @@ from student.models import (
PendingEmailChange, CourseEnrollment, unique_id_for_user,
CourseEnrollmentAllowed, UserStanding, LoginFailures,
create_comments_service_user, PasswordHistory, UserSignupSource,
DashboardConfiguration)
DashboardConfiguration, LinkedInAddToProfileConfiguration)
from student.forms import PasswordResetFormNoActive
from verify_student.models import SoftwareSecurePhotoVerification, MidcourseReverificationWindow
......@@ -187,7 +187,7 @@ def process_survey_link(survey_link, user):
return survey_link.format(UNIQUE_ID=unique_id_for_user(user))
def cert_info(user, course):
def cert_info(user, course, course_mode):
"""
Get the certificate info needed to render the dashboard section for the given
student and course. Returns a dictionary with keys:
......@@ -203,7 +203,7 @@ def cert_info(user, course):
if not course.may_certify():
return {}
return _cert_info(user, course, certificate_status_for_student(user, course.id))
return _cert_info(user, course, certificate_status_for_student(user, course.id), course_mode)
def reverification_info(course_enrollment_pairs, user, statuses):
......@@ -293,7 +293,7 @@ def get_course_enrollment_pairs(user, course_org_filter, org_filter_out_set):
)
def _cert_info(user, course, cert_status):
def _cert_info(user, course, cert_status, course_mode):
"""
Implements the logic for cert_info -- split out for testing.
"""
......@@ -328,7 +328,8 @@ def _cert_info(user, course, cert_status):
'status': status,
'show_download_url': status == 'ready',
'show_disabled_download_button': status == 'generating',
'mode': cert_status.get('mode', None)
'mode': cert_status.get('mode', None),
'linked_in_url': None
}
if (status in ('generating', 'ready', 'notpassing', 'restricted') and
......@@ -350,6 +351,31 @@ def _cert_info(user, course, cert_status):
else:
status_dict['download_url'] = cert_status['download_url']
# getting linkedin URL and then pass the params which appears
# on user profile. if linkedin config is empty don't show the button.
modes_dict = {
"honor": "Honor Code Certificate",
"verified": "Verified Certificate",
"professional": "Professional Certificate",
}
certification_name = u'{type} for {course_name}'.format(
type=modes_dict.get(course_mode, "Certificate"), course_name=course.display_name
).encode('utf-8')
params_dict = {
'pfCertificationName': certification_name,
'pfCertificationUrl': cert_status['download_url'],
}
# following method will construct and return url if current enabled config exists otherwise return None
# In case of None linked-in-button will not appear on dashboard.
status_dict['linked_in_url'] = LinkedInAddToProfileConfiguration.linked_in_dashboard_tracking_code_url(
params_dict
)
if status in ('generating', 'ready', 'notpassing', 'restricted'):
if 'grade' not in cert_status:
# Note: as of 11/20/2012, we know there are students in this state-- cs169.1x,
......@@ -583,9 +609,8 @@ def dashboard(request):
course_enrollment_pairs,
all_course_modes
)
cert_statuses = {
course.id: cert_info(request.user, course)
course.id: cert_info(request.user, course, _enrollment.mode)
for course, _enrollment in course_enrollment_pairs
}
......
......@@ -54,6 +54,14 @@ else:
<a class="btn" href="${cert_status['download_url']}"
title="${_('This link will open/download a PDF document')}">
${_("Download Your {cert_name_short} (PDF)").format(cert_name_short=cert_name_short,)}</a></li>
% if cert_status['linked_in_url']:
<li class="action action-certificate">
<a class="btn" target="_blank" href="${cert_status['linked_in_url']}"
title="${_('Add to LinkedIn Profile')}">
${_("Add Certificate to LinkedIn.")}</a></li>
% endif
% elif cert_status['show_download_url'] and enrollment.mode == 'verified' and cert_status['mode'] == 'honor':
<li class="action">
<p>${_('Since we did not have a valid set of verification photos from you when your {cert_name_long} was generated, we could not grant you a verified {cert_name_short}. An honor code {cert_name_short} has been granted instead.').format(cert_name_short=cert_name_short, cert_name_long=cert_name_long)}</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