Commit ac0d9264 by Matt Drayer

Merge pull request #9717 from edx/ziafazal/SOL-1193

SOL-1193: moved variables from template to view
parents da58885e cf80c07c
...@@ -478,12 +478,12 @@ class CertificatesViewsTests(ModuleStoreTestCase, EventTrackingTestCase): ...@@ -478,12 +478,12 @@ class CertificatesViewsTests(ModuleStoreTestCase, EventTrackingTestCase):
response = self.client.get(test_url) response = self.client.get(test_url)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertContains(response, 'lang: fr') self.assertContains(response, 'lang: fr')
self.assertContains(response, 'course name: {}'.format(self.course.display_name)) self.assertContains(response, 'course name: course_title_0')
# test with second organization template # test with second organization template
response = self.client.get(test_url) response = self.client.get(test_url)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertContains(response, 'lang: fr') self.assertContains(response, 'lang: fr')
self.assertContains(response, 'course name: {}'.format(self.course.display_name)) self.assertContains(response, 'course name: course_title_0')
@override_settings(FEATURES=FEATURES_WITH_CUSTOM_CERTS_ENABLED) @override_settings(FEATURES=FEATURES_WITH_CUSTOM_CERTS_ENABLED)
def test_certificate_custom_template_with_org(self): def test_certificate_custom_template_with_org(self):
...@@ -510,7 +510,7 @@ class CertificatesViewsTests(ModuleStoreTestCase, EventTrackingTestCase): ...@@ -510,7 +510,7 @@ class CertificatesViewsTests(ModuleStoreTestCase, EventTrackingTestCase):
] ]
response = self.client.get(test_url) response = self.client.get(test_url)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertContains(response, 'course name: {}'.format(self.course.display_name)) self.assertContains(response, 'course name: course_title_0')
@override_settings(FEATURES=FEATURES_WITH_CUSTOM_CERTS_ENABLED) @override_settings(FEATURES=FEATURES_WITH_CUSTOM_CERTS_ENABLED)
def test_certificate_custom_template_with_organization(self): def test_certificate_custom_template_with_organization(self):
......
...@@ -4,12 +4,14 @@ Certificate HTML webview. ...@@ -4,12 +4,14 @@ Certificate HTML webview.
from datetime import datetime from datetime import datetime
from uuid import uuid4 from uuid import uuid4
import logging import logging
import urllib
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.http import HttpResponse from django.http import HttpResponse
from django.template import RequestContext from django.template import RequestContext
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.core.urlresolvers import reverse
from courseware.courses import course_image_url from courseware.courses import course_image_url
from edxmako.shortcuts import render_to_response from edxmako.shortcuts import render_to_response
...@@ -105,9 +107,27 @@ def _update_certificate_context(context, course, user, user_certificate): ...@@ -105,9 +107,27 @@ def _update_certificate_context(context, course, user, user_certificate):
context['accomplishment_copy_name'] = user_fullname context['accomplishment_copy_name'] = user_fullname
context['accomplishment_copy_username'] = user.username context['accomplishment_copy_username'] = user.username
context['accomplishment_copy_course_org'] = partner_short_name context['accomplishment_copy_course_org'] = partner_short_name
context['accomplishment_copy_course_name'] = course.display_name course_title_from_cert = context['certificate_data'].get('course_title', '')
context['course_image_url'] = course_image_url(course) accomplishment_copy_course_name = course_title_from_cert if course_title_from_cert else course.display_name
context['share_settings'] = settings.FEATURES.get('SOCIAL_SHARING_SETTINGS', {}) context['accomplishment_copy_course_name'] = accomplishment_copy_course_name
share_settings = settings.FEATURES.get('SOCIAL_SHARING_SETTINGS', {})
context['facebook_share_enabled'] = share_settings.get('CERTIFICATE_FACEBOOK', False)
context['facebook_app_id'] = getattr(settings, "FACEBOOK_APP_ID", None)
context['facebook_share_text'] = share_settings.get(
'CERTIFICATE_FACEBOOK_TEXT',
_("I completed the {course_title} course on {platform_name}.").format(
course_title=accomplishment_copy_course_name,
platform_name=platform_name
)
)
context['twitter_share_enabled'] = share_settings.get('CERTIFICATE_TWITTER', False)
context['twitter_share_text'] = share_settings.get(
'CERTIFICATE_TWITTER_TEXT',
_("I completed a course on {platform_name}. Take a look at my certificate.").format(
platform_name=platform_name
)
)
context['course_number'] = course.number context['course_number'] = course.number
try: try:
badge = BadgeAssertion.objects.get(user=user, course_id=course.location.course_key) badge = BadgeAssertion.objects.get(user=user, course_id=course.location.course_key)
...@@ -374,6 +394,19 @@ def render_html_view(request, user_id, course_id): ...@@ -374,6 +394,19 @@ def render_html_view(request, user_id, course_id):
# Append/Override the existing view context values with request-time values # Append/Override the existing view context values with request-time values
_update_certificate_context(context, course, user, user_certificate) _update_certificate_context(context, course, user, user_certificate)
share_url = request.build_absolute_uri(
reverse(
'certificates:html_view',
kwargs=dict(user_id=str(user_id), course_id=unicode(course_id))
)
)
context['share_url'] = share_url
twitter_url = 'https://twitter.com/intent/tweet?text={twitter_share_text}&url={share_url}'.format(
twitter_share_text=context['twitter_share_text'],
share_url=urllib.quote_plus(share_url)
)
context['twitter_url'] = twitter_url
context['full_course_image_url'] = request.build_absolute_uri(course_image_url(course))
# If enabled, show the LinkedIn "add to profile" button # If enabled, show the LinkedIn "add to profile" button
# Clicking this button sends the user to LinkedIn where they # Clicking this button sends the user to LinkedIn where they
...@@ -389,6 +422,8 @@ def render_html_view(request, user_id, course_id): ...@@ -389,6 +422,8 @@ def render_html_view(request, user_id, course_id):
course_id=unicode(course.id) course_id=unicode(course.id)
)) ))
) )
else:
context['linked_in_url'] = None
# Microsites will need to be able to override any hard coded # Microsites will need to be able to override any hard coded
# content that was put into the context in the # content that was put into the context in the
......
<%! <%!
import urllib
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.core.urlresolvers import reverse from django.template.defaultfilters import escapejs
%> %>
<%namespace name='static' file='../static_content.html'/> <%namespace name='static' file='../static_content.html'/>
<%
accomplishment_course_title = accomplishment_copy_course_name
if certificate_data and certificate_data.get('course_title', ''):
accomplishment_course_title = certificate_data.get('course_title', '')
%>
<%block name="js_extra"> <%block name="js_extra">
<%static:js group='certificates_wv'/> <%static:js group='certificates_wv'/>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
FaceBook.init({"facebook_app_id": '${settings.FACEBOOK_APP_ID}'}); FaceBook.init({"facebook_app_id": '${facebook_app_id}'});
$.ajaxSetup({ $.ajaxSetup({
headers: { headers: {
'X-CSRFToken': $.cookie('csrftoken') 'X-CSRFToken': $.cookie('csrftoken')
...@@ -30,9 +24,7 @@ from django.core.urlresolvers import reverse ...@@ -30,9 +24,7 @@ from django.core.urlresolvers import reverse
social_network: 'LinkedIn' social_network: 'LinkedIn'
}; };
Logger.log('edx.certificate.shared', data); Logger.log('edx.certificate.shared', data);
% if linked_in_url:
window.open('${linked_in_url}'); window.open('${linked_in_url}');
% endif
}); });
}); });
...@@ -53,38 +45,26 @@ from django.core.urlresolvers import reverse ...@@ -53,38 +45,26 @@ from django.core.urlresolvers import reverse
<p class="message-copy copy copy-base emphasized">${accomplishment_banner_congrats}</p> <p class="message-copy copy copy-base emphasized">${accomplishment_banner_congrats}</p>
<div class="message-actions"> <div class="message-actions">
<h3 class="sr-only">${_("Print or share your certificate:")}</h3> <h3 class="sr-only">${_("Print or share your certificate:")}</h3>
% if share_settings: % if facebook_share_enabled:
<% <button class="action action-share-facebook btn btn-overlay btn-small icon-only" id="action-share-facebook"
facebook_share_text = _("I completed the {course_title} course on {platform_name}.").format(course_title=accomplishment_course_title, platform_name=platform_name) onclick="FaceBook.share({
twitter_share_text = _("I completed a course on {platform_name}. Take a look at my certificate.").format(platform_name=platform_name) share_text: '${facebook_share_text | escapejs}',
share_url = request.build_absolute_uri(reverse('certificates:html_view', kwargs=dict(user_id=str(user.id),course_id=unicode(course_id)))) share_link: '${share_url}',
if share_settings.get('CERTIFICATE_FACEBOOK_TEXT', None): picture_link: '${full_course_image_url}',
facebook_share_text = share_settings.get('CERTIFICATE_FACEBOOK_TEXT') description: '${_('Click the link to see my certificate.')}'
if share_settings.get('CERTIFICATE_TWITTER_TEXT', None): });">
twitter_share_text = share_settings.get('CERTIFICATE_TWITTER_TEXT') <i class="icon fa fa-facebook-official" aria-hidden="true"></i>
%> <span class="action-label">${_("Post on Facebook")}</span>
% if share_settings.get('CERTIFICATE_FACEBOOK', False): </button>
<button class="action action-share-facebook btn btn-overlay btn-small icon-only" id="action-share-facebook" %endif
onclick="FaceBook.share({ % if twitter_share_enabled:
share_text: '${facebook_share_text}', <button data-tooltip="${_('Share on Twitter')}"
share_link: '${share_url}', class="action action-share-twitter btn btn-overlay btn-small icon-only"
picture_link: '${request.build_absolute_uri(course_image_url)}', title="${_('Share on Twitter')}"
description: '${_('Click the link to see my certificate.')}' onclick="popupWindow('${twitter_url}', 'tweetWindow', 640, 480); return false;">
});"> <i class="icon fa fa-twitter" aria-hidden="true"></i>
<i class="icon fa fa-facebook-official" aria-hidden="true"></i> <span class="action-label">${_("Tweet this Accomplishment. Pop up window.")}</span>
<span class="action-label">${_("Post on Facebook")}</span> </button>
</button>
%endif
% if share_settings.get('CERTIFICATE_TWITTER', False):
<% twitter_url = 'https://twitter.com/intent/tweet?text=' + twitter_share_text + '&url='+ urllib.quote_plus(share_url)%>
<button data-tooltip="${_('Share on Twitter')}"
class="action action-share-twitter btn btn-overlay btn-small icon-only"
title="${_('Share on Twitter')}"
onclick="popupWindow('${twitter_url}', 'tweetWindow', 640, 480); return false;">
<i class="icon fa fa-twitter" aria-hidden="true"></i>
<span class="action-label">${_("Tweet this Accomplishment. Pop up window.")}</span>
</button>
%endif
%endif %endif
%if linked_in_url: %if linked_in_url:
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<header class="header-app" role="banner"> <header class="header-app" role="banner">
<h1 class="header-app-title"> <h1 class="header-app-title">
<a class="logo" href="${logo_url}"> <a class="logo" href="${logo_url}">
<img class="logo-img" src="${logo_src}" alt="${_('{platform_name} Home').format(platform_name=settings.PLATFORM_NAME)}" /> <img class="logo-img" src="${logo_src}" alt="${_('{platform_name} Home').format(platform_name=platform_name)}" />
</a> </a>
<span class="sr-only">${logo_subtitle}</span> <span class="sr-only">${logo_subtitle}</span>
</h1> </h1>
......
<%! from django.utils.translation import ugettext as _ %> <%! from django.utils.translation import ugettext as _ %>
<%namespace name='static' file='../static_content.html'/> <%namespace name='static' file='../static_content.html'/>
<% <%
accomplishment_course_title = accomplishment_copy_course_name
if certificate_data and certificate_data.get('course_title', ''):
accomplishment_course_title = certificate_data.get('course_title', '')
course_mode_class = course_mode if course_mode else '' course_mode_class = course_mode if course_mode else ''
%> %>
...@@ -33,7 +30,7 @@ course_mode_class = course_mode if course_mode else '' ...@@ -33,7 +30,7 @@ course_mode_class = course_mode if course_mode else ''
<span class="accomplishment-course hd-1 emphasized"> <span class="accomplishment-course hd-1 emphasized">
<span class="accomplishment-course-org">${accomplishment_copy_course_org} </span> <span class="accomplishment-course-org">${accomplishment_copy_course_org} </span>
<span class="accomplishment-course-number">${course_number}</span>: <span class="accomplishment-course-number">${course_number}</span>:
<span class="accomplishment-course-name">${accomplishment_course_title}</span> <span class="accomplishment-course-name">${accomplishment_copy_course_name}</span>
</span> </span>
</p> </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