Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions cms/djangoapps/contentstore/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,17 @@ def lms_link_for_certificate_web_view_test(self):
mode = 'professional'

self.assertEqual(
utils.get_lms_link_for_certificate_web_view(dummy_user, course_key, mode),
"//localhost:8000/certificates/user/{user_id}/course/{course_key}?preview={mode}".format(
user_id=dummy_user,
utils.get_lms_link_for_certificate_web_view(course_key, mode),
"//localhost:8000/certificates/course/{course_key}?preview={mode}".format(
course_key=course_key,
mode=mode
)
)

with with_site_configuration_context(configuration={"course_org_filter": "mitX", "LMS_BASE": "dummyhost:8000"}):
self.assertEqual(
utils.get_lms_link_for_certificate_web_view(dummy_user, course_key, mode),
"//dummyhost:8000/certificates/user/{user_id}/course/{course_key}?preview={mode}".format(
user_id=dummy_user,
utils.get_lms_link_for_certificate_web_view(course_key, mode),
"//dummyhost:8000/certificates/course/{course_key}?preview={mode}".format(
course_key=course_key,
mode=mode
)
Expand Down
5 changes: 2 additions & 3 deletions cms/djangoapps/contentstore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def get_lms_link_for_item(location, preview=False):
)


def get_lms_link_for_certificate_web_view(user_id, course_key, mode):
def get_lms_link_for_certificate_web_view(course_key, mode):
"""
Returns the url to the certificate web view.
"""
Expand All @@ -150,9 +150,8 @@ def get_lms_link_for_certificate_web_view(user_id, course_key, mode):
if lms_base is None:
return None

return u"//{certificate_web_base}/certificates/user/{user_id}/course/{course_id}?preview={mode}".format(
return u"//{certificate_web_base}/certificates/course/{course_id}?preview={mode}".format(
certificate_web_base=lms_base,
user_id=user_id,
course_id=six.text_type(course_key),
mode=mode
)
Expand Down
1 change: 0 additions & 1 deletion cms/djangoapps/contentstore/views/certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ def certificates_list_handler(request, course_key_string):

if has_certificate_modes:
certificate_web_view_url = get_lms_link_for_certificate_web_view(
user_id=request.user.id,
course_key=course_key,
mode=course_modes[0] # CourseMode.modes_for_course returns default mode if doesn't find anyone.
)
Expand Down
6 changes: 2 additions & 4 deletions cms/djangoapps/contentstore/views/tests/test_certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,18 +263,16 @@ def test_cannot_create_certificate_if_user_has_no_write_permissions(self):
@override_settings(LMS_BASE=None)
def test_no_lms_base_for_certificate_web_view_link(self):
test_link = get_lms_link_for_certificate_web_view(
user_id=self.user.id,
course_key=self.course.id,
mode='honor'
)
self.assertEqual(test_link, None)

@override_settings(LMS_BASE="lms_base_url")
def test_lms_link_for_certificate_web_view(self):
test_url = "//lms_base_url/certificates/user/" \
+ str(self.user.id) + "/course/" + six.text_type(self.course.id) + '?preview=honor'
test_url = "//lms_base_url/certificates/" \
"course/" + six.text_type(self.course.id) + '?preview=honor'
link = get_lms_link_for_certificate_web_view(
user_id=self.user.id,
course_key=self.course.id,
mode='honor'
)
Expand Down
4 changes: 2 additions & 2 deletions cms/templates/js/group-configuration-details.underscore
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@

<% if(showGroups) { %>
<% allocation = Math.floor(100 / groups.length) %>
<ol class="collection-items groups groups-<%= index %>">
<ol class="collection-items groups groups-<%- index %>">
<% groups.each(function(group, groupIndex) { %>
<li class="item group group-<%= groupIndex %>">
<li class="item group group-<%- groupIndex %>">
<span class="name group-name"><%- group.get('name') %></span>
<span class="meta group-allocation"><%- allocation %>%</span>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<%- gettext('You have done a dry run of force publishing the course. Nothing has changed. Had you run it, the following course versions would have been change.') %>
</div>
<div class="main-output">
<%= StringUtils.interpolate(
<%- StringUtils.interpolate(
gettext('The published branch version, {published}, was reset to the draft branch version, {draft}.'),
{
published: current_versions['published-branch'],
Expand Down
6 changes: 3 additions & 3 deletions cms/templates/js/mock/mock-xmodule-editor.underscore
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

<script id="metadata-string-entry" type="text/template">
<div class="wrapper-comp-setting">
\t<label class="label setting-label" for="<%= uniqueId %>"><%= model.get('display_name') %></label>
\t<input class="input setting-input" type="text" id="<%= uniqueId %>" value='<%= model.get("value") %>'/>
\t<label class="label setting-label" for="<%- uniqueId %>"><%- model.get('display_name') %></label>
\t<input class="input setting-input" type="text" id="<%- uniqueId %>" value='<%- model.get("value") %>'/>
\t<button class="action setting-clear inactive" type="button" name="setting-clear" value="Clear" data-tooltip="Clear">
<span class="icon fa fa-undo" aria-hidden="true"></span><span class="sr">"Clear Value"</span>
</button>
</div>
<span class="tip setting-help"><%= model.get('help') %></span>
<span class="tip setting-help"><%- model.get('help') %></span>

</script>

Expand Down
6 changes: 3 additions & 3 deletions cms/templates/js/publish-editor.underscore
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<% _.each(xblockInfo.get('child_info').children, function(subsection) { %>
<% if (subsection.isPublishable()) { %>
<li class="outline-item outline-subsection">
<h4 class="subsection-title item-title"><%= subsection.get('display_name') %></h4>
<h4 class="subsection-title item-title"><%- subsection.get('display_name') %></h4>
<div class="subsection-content">
<ol class="list-units">
<% _.each(subsection.get('child_info').children, function(unit) { %>
<% if (unit.isPublishable()) { %>
<li class="outline-item outline-unit">
<span class="unit-title item-title"><%= unit.get('display_name') %></span>
<span class="unit-title item-title"><%- unit.get('display_name') %></span>
</li>
<% } %>
<% }); %>
Expand All @@ -27,7 +27,7 @@
<% _.each(xblockInfo.get('child_info').children, function(unit) { %>
<% if (unit.isPublishable()) { %>
<li class="outline-item outline-unit">
<span class="unit-title item-title"><%= unit.get('display_name') %></span>
<span class="unit-title item-title"><%- unit.get('display_name') %></span>
</li>
<% } %>
<% }); %>
Expand Down
24 changes: 12 additions & 12 deletions cms/templates/js/unit-outline.underscore
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<% if (parentInfo) { %>
<li class="outline-item outline-<%= xblockType %> <%= visibilityClass %> <%= xblockInfo.get('id') === currentUnitId ? 'is-current' : '' %>"
data-parent="<%= parentInfo.get('id') %>" data-locator="<%= xblockInfo.get('id') %>">
<div class="<%= xblockType %>-header">
<h3 class="<%= xblockType %>-header-details">
<span class="<%= xblockType %>-title item-title">
<a href="<%= xblockInfo.get('studio_url') %>"><%- xblockInfo.get('display_name') %></a>
<li class="outline-item outline-<%- xblockType %> <%- visibilityClass %> <%- xblockInfo.get('id') === currentUnitId ? 'is-current' : '' %>"
data-parent="<%- parentInfo.get('id') %>" data-locator="<%- xblockInfo.get('id') %>">
<div class="<%- xblockType %>-header">
<h3 class="<%- xblockType %>-header-details">
<span class="<%- xblockType %>-title item-title">
<a href="<%- xblockInfo.get('studio_url') %>"><%- xblockInfo.get('display_name') %></a>
</span>
</h3>
</div>
<% } %>

<div class="<%= xblockType %>-content outline-content">
<ol class="<%= typeListClass %>">
<div class="<%- xblockType %>-content outline-content">
<ol class="<%- typeListClass %>">
</ol>
<% if (childType) { %>
<div class="add-<%= childType %> add-item">
<a href="#" class="button button-new" data-category="<%= childCategory %>"
data-parent="<%= xblockInfo.get('id') %>" data-default-name="<%= defaultNewChildName %>">
<span class="icon fa fa-plus" aria-hidden="true"></span><%= addChildLabel %>
<div class="add-<%- childType %> add-item">
<a href="#" class="button button-new" data-category="<%- childCategory %>"
data-parent="<%- xblockInfo.get('id') %>" data-default-name="<%- defaultNewChildName %>">
<span class="icon fa fa-plus" aria-hidden="true"></span><%- addChildLabel %>
</a>
</div>
<% } %>
Expand Down
4 changes: 2 additions & 2 deletions cms/templates/js/video/transcripts/file-upload.underscore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<form class="file-chooser" action="/transcripts/upload"
method="post" enctype="multipart/form-data">
<input type="file" class="file-input" name="transcript-file"
accept="<%= _.map(ext, function(val){ return '.' + val; }).join(', ') %>">
<input type="hidden" name="locator" value="<%= component_locator %>">
accept="<%- _.map(ext, function(val){ return '.' + val; }).join(', ') %>">
<input type="hidden" name="locator" value="<%- component_locator %>">
</form>
4 changes: 2 additions & 2 deletions cms/templates/js/xblock-validation-messages.underscore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var summaryMessage = validation.get("summary");
var aggregateMessageType = summaryMessage.type;
var aggregateValidationClass = aggregateMessageType === "error"? "has-errors" : "has-warnings";
%>
<div class="xblock-message validation <%= aggregateValidationClass %> <%= additionalClasses %>">
<div class="xblock-message validation <%- aggregateValidationClass %> <%- additionalClasses %>">
<p class="<%- aggregateMessageType %>"><span class="icon fa <%- getIcon(aggregateMessageType) %>" aria-hidden="true"></span>
<%- summaryMessage.text %>
<% if (summaryMessage.action_class) { %>
Expand All @@ -25,7 +25,7 @@ var aggregateValidationClass = aggregateMessageType === "error"? "has-errors" :
var messageType = message.type
var messageTypeDisplayName = getDisplayName(messageType)
%>
<li class="xblock-message-item <%= messageType %>">
<li class="xblock-message-item <%- messageType %>">
<span class="message-text">
<% if (messageTypeDisplayName) { %>
<span class="sr"><%- messageTypeDisplayName %>:</span>
Expand Down
7 changes: 6 additions & 1 deletion lms/djangoapps/badges/events/course_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging

import six

from django.urls import reverse
from django.utils.text import slugify
from django.utils.translation import ugettext_lazy as _
Expand All @@ -15,6 +16,7 @@
from badges.utils import requires_badges_enabled, site_prefix
from xmodule.modulestore.django import modulestore


LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -63,8 +65,11 @@ def evidence_url(user_id, course_key):
event.
"""
course_id = six.text_type(course_key)
# avoid circular import problems
from lms.djangoapps.certificates.models import GeneratedCertificate
cert = GeneratedCertificate.eligible_certificates.get(user__id=int(user_id), course_id=course_id)
return site_prefix() + reverse(
'certificates:html_view', kwargs={'user_id': user_id, 'course_id': course_id}) + '?evidence_visit=1'
'certificates:render_cert_by_uuid', kwargs={'certificate_uuid': cert.verify_uuid}) + '?evidence_visit=1'


def criteria(course_key):
Expand Down
20 changes: 15 additions & 5 deletions lms/djangoapps/badges/events/tests/test_course_complete.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
Tests for the course completion helper functions.
"""


from datetime import datetime
from uuid import uuid4

from badges.events import course_complete
from lms.djangoapps.certificates.models import GeneratedCertificate
from student.tests.factories import UserFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
Expand Down Expand Up @@ -64,9 +64,19 @@ def test_evidence_url(self):
Make sure the evidence URL points to the right place.
"""
user = UserFactory.create()
cert = GeneratedCertificate.eligible_certificates.create(
user=user,
course_id=self.course_key,
download_uuid=uuid4(),
grade="0.95",
key='the_key',
distinction=True,
status='downloadable',
mode='honor',
name=user.profile.name,
verify_uuid=uuid4().hex
)
self.assertEqual(
'https://edx.org/certificates/user/{user_id}/course/{course_key}?evidence_visit=1'.format(
user_id=user.id, course_key=self.course_key
),
'https://edx.org/certificates/{}?evidence_visit=1'.format(cert.verify_uuid),
course_complete.evidence_url(user.id, self.course_key)
)
23 changes: 13 additions & 10 deletions lms/djangoapps/certificates/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ def certificate_downloadable_status(student, course_key):

if current_status['status'] == CertificateStatuses.downloadable and may_view_certificate:
response_data['is_downloadable'] = True
response_data['download_url'] = current_status['download_url'] or get_certificate_url(student.id, course_key)
response_data['download_url'] = current_status['download_url'] or get_certificate_url(
student.id, course_key, current_status['uuid']
)
response_data['is_pdf_certificate'] = bool(current_status['download_url'])
response_data['uuid'] = current_status['uuid']

Expand Down Expand Up @@ -472,13 +474,13 @@ def _course_from_key(course_key):
return CourseOverview.get_from_id(_safe_course_key(course_key))


def _certificate_html_url(user_id, course_id, uuid):
if uuid:
return reverse('certificates:render_cert_by_uuid', kwargs={'certificate_uuid': uuid})
elif user_id and course_id:
kwargs = {"user_id": str(user_id), "course_id": six.text_type(course_id)}
return reverse('certificates:html_view', kwargs=kwargs)
return ''
def _certificate_html_url(uuid):
"""
Returns uuid based certificate URL.
"""
return reverse(
'certificates:render_cert_by_uuid', kwargs={'certificate_uuid': uuid}
) if uuid else ''


def _certificate_download_url(user_id, course_id, user_certificate=None):
Expand Down Expand Up @@ -515,7 +517,7 @@ def get_certificate_url(user_id=None, course_id=None, uuid=None, user_certificat
return url

if has_html_certificates_enabled(course):
url = _certificate_html_url(user_id, course_id, uuid)
url = _certificate_html_url(uuid)
else:
url = _certificate_download_url(user_id, course_id, user_certificate=user_certificate)
return url
Expand Down Expand Up @@ -631,10 +633,11 @@ def emit_certificate_event(event_name, user, course_id, course=None, event_data=
'org_id': course.org,
'course_id': six.text_type(course_id)
}

data = {
'user_id': user.id,
'course_id': six.text_type(course_id),
'certificate_url': get_certificate_url(user.id, course_id)
'certificate_url': get_certificate_url(user.id, course_id, uuid=event_data['certificate_id'])
}
event_data = event_data or {}
event_data.update(data)
Expand Down
15 changes: 5 additions & 10 deletions lms/djangoapps/certificates/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,7 @@ def test_with_downloadable_web_cert(self):
'is_downloadable': True,
'is_generating': False,
'is_unverified': False,
'download_url': '/certificates/user/{user_id}/course/{course_id}'.format(
user_id=self.student.id,
course_id=self.course.id,
),
'download_url': '/certificates/{uuid}'.format(uuid=cert_status['uuid']),
'is_pdf_certificate': False,
'uuid': cert_status['uuid']
}
Expand Down Expand Up @@ -496,16 +493,14 @@ def test_get_web_certificate_url(self):
self.assertEqual(expected_url, cert_url)

expected_url = reverse(
'certificates:html_view',
kwargs={
"user_id": str(self.student.id),
"course_id": six.text_type(self.web_cert_course.id),
}
'certificates:render_cert_by_uuid',
kwargs=dict(certificate_uuid=self.uuid)
)

cert_url = certs_api.get_certificate_url(
user_id=self.student.id,
course_id=self.web_cert_course.id
course_id=self.web_cert_course.id,
uuid=self.uuid
)
self.assertEqual(expected_url, cert_url)

Expand Down
7 changes: 5 additions & 2 deletions lms/djangoapps/certificates/tests/test_support_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@


import json
from uuid import uuid4

import ddt
import six

from django.conf import settings
from django.test.utils import override_settings
from django.urls import reverse
Expand Down Expand Up @@ -85,6 +87,7 @@ def setUp(self):
status=self.CERT_STATUS,
mode=self.CERT_MODE,
download_url=self.CERT_DOWNLOAD_URL,
verify_uuid=uuid4().hex
)

# Login as support staff
Expand Down Expand Up @@ -226,8 +229,8 @@ def test_download_link(self):
self.assertEqual(
retrieved_cert["download_url"],
reverse(
'certificates:html_view',
kwargs={"user_id": self.student.id, "course_id": self.course.id}
'certificates:render_cert_by_uuid',
kwargs={"certificate_uuid": self.cert.verify_uuid}
)
)
self.assertTrue(retrieved_cert["regenerate"])
Expand Down
Loading