moved variables from template to view
fixed broken tests and quality violations moved twitter_url to view also escaped string for js
This commit is contained in:
@@ -477,12 +477,12 @@ class CertificatesViewsTests(ModuleStoreTestCase, EventTrackingTestCase):
|
||||
response = self.client.get(test_url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
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
|
||||
response = self.client.get(test_url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
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)
|
||||
def test_certificate_custom_template_with_org(self):
|
||||
@@ -503,7 +503,7 @@ class CertificatesViewsTests(ModuleStoreTestCase, EventTrackingTestCase):
|
||||
]
|
||||
response = self.client.get(test_url)
|
||||
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)
|
||||
def test_certificate_custom_template_with_course_mode(self):
|
||||
|
||||
@@ -4,12 +4,14 @@ Certificate HTML webview.
|
||||
from datetime import datetime
|
||||
from uuid import uuid4
|
||||
import logging
|
||||
import urllib
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.http import HttpResponse
|
||||
from django.template import RequestContext
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
from courseware.courses import course_image_url
|
||||
from edxmako.shortcuts import render_to_response
|
||||
@@ -105,9 +107,27 @@ def _update_certificate_context(context, course, user, user_certificate):
|
||||
context['accomplishment_copy_name'] = user_fullname
|
||||
context['accomplishment_copy_username'] = user.username
|
||||
context['accomplishment_copy_course_org'] = partner_short_name
|
||||
context['accomplishment_copy_course_name'] = course.display_name
|
||||
context['course_image_url'] = course_image_url(course)
|
||||
context['share_settings'] = settings.FEATURES.get('SOCIAL_SHARING_SETTINGS', {})
|
||||
course_title_from_cert = context['certificate_data'].get('course_title', '')
|
||||
accomplishment_copy_course_name = course_title_from_cert if course_title_from_cert else course.display_name
|
||||
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
|
||||
try:
|
||||
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):
|
||||
|
||||
# Append/Override the existing view context values with request-time values
|
||||
_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
|
||||
# Clicking this button sends the user to LinkedIn where they
|
||||
@@ -389,6 +422,8 @@ def render_html_view(request, user_id, course_id):
|
||||
course_id=unicode(course.id)
|
||||
))
|
||||
)
|
||||
else:
|
||||
context['linked_in_url'] = None
|
||||
|
||||
# Microsites will need to be able to override any hard coded
|
||||
# content that was put into the context in the
|
||||
|
||||
@@ -1,19 +1,13 @@
|
||||
<%!
|
||||
import urllib
|
||||
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'/>
|
||||
<%
|
||||
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">
|
||||
<%static:js group='certificates_wv'/>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
FaceBook.init({"facebook_app_id": '${settings.FACEBOOK_APP_ID}'});
|
||||
FaceBook.init({"facebook_app_id": '${facebook_app_id}'});
|
||||
$.ajaxSetup({
|
||||
headers: {
|
||||
'X-CSRFToken': $.cookie('csrftoken')
|
||||
@@ -30,9 +24,7 @@ from django.core.urlresolvers import reverse
|
||||
social_network: 'LinkedIn'
|
||||
};
|
||||
Logger.log('edx.certificate.shared', data);
|
||||
% if linked_in_url:
|
||||
window.open('${linked_in_url}');
|
||||
% endif
|
||||
});
|
||||
});
|
||||
|
||||
@@ -53,38 +45,26 @@ from django.core.urlresolvers import reverse
|
||||
<p class="message-copy copy copy-base emphasized">${accomplishment_banner_congrats}</p>
|
||||
<div class="message-actions">
|
||||
<h3 class="sr-only">${_("Print or share your certificate:")}</h3>
|
||||
% if share_settings:
|
||||
<%
|
||||
facebook_share_text = _("I completed the {course_title} course on {platform_name}.").format(course_title=accomplishment_course_title, platform_name=platform_name)
|
||||
twitter_share_text = _("I completed a course on {platform_name}. Take a look at my certificate.").format(platform_name=platform_name)
|
||||
share_url = request.build_absolute_uri(reverse('certificates:html_view', kwargs=dict(user_id=str(user.id),course_id=unicode(course_id))))
|
||||
if share_settings.get('CERTIFICATE_FACEBOOK_TEXT', None):
|
||||
facebook_share_text = share_settings.get('CERTIFICATE_FACEBOOK_TEXT')
|
||||
if share_settings.get('CERTIFICATE_TWITTER_TEXT', None):
|
||||
twitter_share_text = share_settings.get('CERTIFICATE_TWITTER_TEXT')
|
||||
%>
|
||||
% if share_settings.get('CERTIFICATE_FACEBOOK', False):
|
||||
<button class="action action-share-facebook btn btn-overlay btn-small icon-only" id="action-share-facebook"
|
||||
onclick="FaceBook.share({
|
||||
share_text: '${facebook_share_text}',
|
||||
share_link: '${share_url}',
|
||||
picture_link: '${request.build_absolute_uri(course_image_url)}',
|
||||
description: '${_('Click the link to see my certificate.')}'
|
||||
});">
|
||||
<i class="icon fa fa-facebook-official" aria-hidden="true"></i>
|
||||
<span class="action-label">${_("Post on Facebook")}</span>
|
||||
</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
|
||||
% if facebook_share_enabled:
|
||||
<button class="action action-share-facebook btn btn-overlay btn-small icon-only" id="action-share-facebook"
|
||||
onclick="FaceBook.share({
|
||||
share_text: '${facebook_share_text | escapejs}',
|
||||
share_link: '${share_url}',
|
||||
picture_link: '${full_course_image_url}',
|
||||
description: '${_('Click the link to see my certificate.')}'
|
||||
});">
|
||||
<i class="icon fa fa-facebook-official" aria-hidden="true"></i>
|
||||
<span class="action-label">${_("Post on Facebook")}</span>
|
||||
</button>
|
||||
%endif
|
||||
% if twitter_share_enabled:
|
||||
<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
|
||||
|
||||
%if linked_in_url:
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<header class="header-app" role="banner">
|
||||
<h1 class="header-app-title">
|
||||
<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>
|
||||
<span class="sr-only">${logo_subtitle}</span>
|
||||
</h1>
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
<%! from django.utils.translation import ugettext as _ %>
|
||||
<%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 ''
|
||||
%>
|
||||
|
||||
@@ -33,7 +30,7 @@ course_mode_class = course_mode if course_mode else ''
|
||||
<span class="accomplishment-course hd-1 emphasized">
|
||||
<span class="accomplishment-course-org">${accomplishment_copy_course_org} </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>
|
||||
</p>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user