Skip to content

Commit 613d845

Browse files
pkulkarkxitij2000
authored andcommitted
feat: Make course description editable in certs
Adds the ability to edit the default course description shown in certificates. (cherry picked from commit a89baafe0575c94fac0cb4ce9db1d38ce0b71bc6) (cherry picked from commit b16c266)
1 parent 58ecc18 commit 613d845

File tree

7 files changed

+34
-16
lines changed

7 files changed

+34
-16
lines changed

cms/djangoapps/contentstore/views/certificates.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ def serialize_certificate(certificate):
231231
# Some keys are not required, such as the title override...
232232
if certificate_data.get('course_title'):
233233
certificate_response["course_title"] = certificate_data['course_title']
234+
if certificate_data.get('course_description'):
235+
certificate_response['course_description'] = certificate_data['course_description']
234236

235237
return certificate_response
236238

cms/static/js/certificates/models/certificate.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function(_, Backbone, BackboneRelational, BackboneAssociations, gettext, CoffeeS
1818
defaults: {
1919
// Metadata fields currently displayed in web forms
2020
course_title: '',
21+
course_description: '',
2122

2223
// Metadata fields not currently displayed in web forms
2324
name: 'Name of the certificate',

cms/static/js/certificates/views/certificate_editor.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function($, _, Backbone, gettext,
2424
'change .collection-name-input': 'setName',
2525
'change .certificate-description-input': 'setDescription',
2626
'change .certificate-course-title-input': 'setCourseTitle',
27+
'change .certificate-course-description-input': 'setCourseDescription',
2728
'focus .input-text': 'onFocus',
2829
'blur .input-text': 'onBlur',
2930
submit: 'setAndClose',
@@ -103,6 +104,7 @@ function($, _, Backbone, gettext,
103104
name: this.model.get('name'),
104105
description: this.model.get('description'),
105106
course_title: this.model.get('course_title'),
107+
course_description: this.model.get('course_description'),
106108
org_logo_path: this.model.get('org_logo_path'),
107109
is_active: this.model.get('is_active'),
108110
isNew: this.model.isNew()
@@ -143,11 +145,22 @@ function($, _, Backbone, gettext,
143145
);
144146
},
145147

148+
setCourseDescription: function(event) {
149+
// Updates the indicated model field (still requires persistence on server)
150+
if (event && event.preventDefault) { event.preventDefault(); }
151+
this.model.set(
152+
'course_description',
153+
this.$('.certificate-course-description-input').val(),
154+
{silent: true}
155+
);
156+
},
157+
146158
setValues: function() {
147159
// Update the specified values in the local model instance
148160
this.setName();
149161
this.setDescription();
150162
this.setCourseTitle();
163+
this.setCourseDescription();
151164
return this;
152165
}
153166
});

cms/templates/js/certificate-details.underscore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
<span class="certificate-value"><%- course_title %></span>
3030
</p>
3131
<% } %>
32+
<% if (course_description) { %>
33+
<p class="course-description">
34+
<span class="certificate-label"><b><%- gettext('Course Description') %>: </b></span>
35+
<span class="certificate-value"><%- course_description %></span>
36+
</p>
37+
<% } %>
3238
</div>
3339

3440
<div class='course-number-section pull-left'>

cms/templates/js/certificate-editor.underscore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
<input id="certificate-course-title-<%- uniqueId %>" class="certificate-course-title-input input-text" name="certificate-course-title" type="text" placeholder="<%- gettext("Course title") %>" value="<%- course_title %>" aria-describedby="certificate-course-title-<%-uniqueId %>-tip" />
3232
<span id="certificate-course-title-<%- uniqueId %>-tip" class="tip tip-stacked"><%- gettext("Specify an alternative to the official course title to display on certificates. Leave blank to use the official course title.") %></span>
3333
</div>
34+
<div class="input-wrap field text add-certification-course-description">
35+
<label for="certificate-course-description-<%- uniqueId %>"><%- gettext("Course Description") %></label>
36+
<input id="certificate-course-description-<%- uniqueId %>" class="certificate-course-description-input input-text" name="certificate-course-description" type="text" placeholder="<%- gettext("Course Description") %>" value="<%- course_description %>" aria-describedby="certificate-course-description-<%-uniqueId %>-tip" />
37+
<span id="certificate-course-description-<%- uniqueId %>-tip" class="tip tip-stacked"><%- gettext("Specify an alternative to the official course description to display on certificates. Leave blank to use default text.") %></span>
38+
</div>
3439
</fieldset>
3540
<header>
3641
<h2 class="title title-2"><%- gettext("Certificate Signatories") %></h2>

lms/djangoapps/certificates/tests/test_webview_views.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def _add_course_certificates(self, count=1, signatory_count=0, is_active=True):
140140
'name': 'Name ' + str(i),
141141
'description': 'Description ' + str(i),
142142
'course_title': 'course_title_' + str(i),
143+
'course_description': 'course_description_' + str(i),
143144
'org_logo_path': f'/t4x/orgX/testX/asset/org-logo-{i}.png',
144145
'signatories': signatories,
145146
'version': 1,
@@ -460,11 +461,6 @@ def test_rendering_course_organization_data(self):
460461
uuid=self.cert.verify_uuid
461462
)
462463
response = self.client.get(test_url)
463-
self.assertContains(
464-
response,
465-
'a course of study offered by test_organization, an online learning initiative of test organization',
466-
)
467-
self.assertNotContains(response, 'a course of study offered by testorg')
468464
self.assertContains(response, f'<title>test_organization {self.course.number} Certificate |')
469465
self.assertContains(response, 'logo_test1.png')
470466

@@ -549,21 +545,13 @@ def test_rendering_maximum_data(self):
549545
self.assertContains(response, '<a class="logo" href="http://test_site.localhost">')
550546
# Test an item from course info
551547
self.assertContains(response, 'course_title_0')
548+
# Test an item from course description
549+
self.assertContains(response, 'course_description_0')
552550
# Test an item from user info
553551
self.assertContains(response, f"{self.user.profile.name}, you earned a certificate!")
554552
# Test an item from social info
555553
self.assertContains(response, "Post on Facebook")
556554
self.assertContains(response, "Share on Twitter")
557-
# Test an item from certificate/org info
558-
self.assertContains(
559-
response,
560-
"a course of study offered by {partner_short_name}, "
561-
"an online learning initiative of "
562-
"{partner_long_name}.".format(
563-
partner_short_name=short_org_name,
564-
partner_long_name=long_org_name,
565-
),
566-
)
567555
# Test item from badge info
568556
self.assertContains(response, "Add to Mozilla Backpack")
569557
# Test item from site configuration

lms/djangoapps/certificates/views/webview.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,10 @@ def _update_course_context(request, context, course, platform_name):
254254
course_number = course.display_coursenumber if course.display_coursenumber else course.number
255255
context['course_number'] = course_number
256256
context['idv_enabled_for_certificates'] = settings.FEATURES.get('ENABLE_CERTIFICATES_IDV_REQUIREMENT')
257-
if context['organization_long_name']:
257+
course_description_override = context['certificate_data'].get('course_description', '')
258+
if course_description_override:
259+
context['accomplishment_copy_course_description'] = course_description_override
260+
elif context['organization_long_name']:
258261
# Translators: This text represents the description of course
259262
context['accomplishment_copy_course_description'] = _('a course of study offered by {partner_short_name}, '
260263
'an online learning initiative of '

0 commit comments

Comments
 (0)