Skip to content

Commit

Permalink
feat: Make course description editable in certs
Browse files Browse the repository at this point in the history
Adds the ability to edit the default course description
shown in certificates.

(cherry picked from commit a89baafe0575c94fac0cb4ce9db1d38ce0b71bc6)
(cherry picked from commit b16c266)
  • Loading branch information
pkulkark authored and xitij2000 committed Jun 23, 2023
1 parent 58ecc18 commit 613d845
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 16 deletions.
2 changes: 2 additions & 0 deletions cms/djangoapps/contentstore/views/certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ def serialize_certificate(certificate):
# Some keys are not required, such as the title override...
if certificate_data.get('course_title'):
certificate_response["course_title"] = certificate_data['course_title']
if certificate_data.get('course_description'):
certificate_response['course_description'] = certificate_data['course_description']

return certificate_response

Expand Down
1 change: 1 addition & 0 deletions cms/static/js/certificates/models/certificate.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function(_, Backbone, BackboneRelational, BackboneAssociations, gettext, CoffeeS
defaults: {
// Metadata fields currently displayed in web forms
course_title: '',
course_description: '',

// Metadata fields not currently displayed in web forms
name: 'Name of the certificate',
Expand Down
13 changes: 13 additions & 0 deletions cms/static/js/certificates/views/certificate_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function($, _, Backbone, gettext,
'change .collection-name-input': 'setName',
'change .certificate-description-input': 'setDescription',
'change .certificate-course-title-input': 'setCourseTitle',
'change .certificate-course-description-input': 'setCourseDescription',
'focus .input-text': 'onFocus',
'blur .input-text': 'onBlur',
submit: 'setAndClose',
Expand Down Expand Up @@ -103,6 +104,7 @@ function($, _, Backbone, gettext,
name: this.model.get('name'),
description: this.model.get('description'),
course_title: this.model.get('course_title'),
course_description: this.model.get('course_description'),
org_logo_path: this.model.get('org_logo_path'),
is_active: this.model.get('is_active'),
isNew: this.model.isNew()
Expand Down Expand Up @@ -143,11 +145,22 @@ function($, _, Backbone, gettext,
);
},

setCourseDescription: function(event) {
// Updates the indicated model field (still requires persistence on server)
if (event && event.preventDefault) { event.preventDefault(); }
this.model.set(
'course_description',
this.$('.certificate-course-description-input').val(),
{silent: true}
);
},

setValues: function() {
// Update the specified values in the local model instance
this.setName();
this.setDescription();
this.setCourseTitle();
this.setCourseDescription();
return this;
}
});
Expand Down
6 changes: 6 additions & 0 deletions cms/templates/js/certificate-details.underscore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
<span class="certificate-value"><%- course_title %></span>
</p>
<% } %>
<% if (course_description) { %>
<p class="course-description">
<span class="certificate-label"><b><%- gettext('Course Description') %>: </b></span>
<span class="certificate-value"><%- course_description %></span>
</p>
<% } %>
</div>

<div class='course-number-section pull-left'>
Expand Down
5 changes: 5 additions & 0 deletions cms/templates/js/certificate-editor.underscore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
<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" />
<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>
</div>
<div class="input-wrap field text add-certification-course-description">
<label for="certificate-course-description-<%- uniqueId %>"><%- gettext("Course Description") %></label>
<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" />
<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>
</div>
</fieldset>
<header>
<h2 class="title title-2"><%- gettext("Certificate Signatories") %></h2>
Expand Down
18 changes: 3 additions & 15 deletions lms/djangoapps/certificates/tests/test_webview_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def _add_course_certificates(self, count=1, signatory_count=0, is_active=True):
'name': 'Name ' + str(i),
'description': 'Description ' + str(i),
'course_title': 'course_title_' + str(i),
'course_description': 'course_description_' + str(i),
'org_logo_path': f'/t4x/orgX/testX/asset/org-logo-{i}.png',
'signatories': signatories,
'version': 1,
Expand Down Expand Up @@ -460,11 +461,6 @@ def test_rendering_course_organization_data(self):
uuid=self.cert.verify_uuid
)
response = self.client.get(test_url)
self.assertContains(
response,
'a course of study offered by test_organization, an online learning initiative of test organization',
)
self.assertNotContains(response, 'a course of study offered by testorg')
self.assertContains(response, f'<title>test_organization {self.course.number} Certificate |')
self.assertContains(response, 'logo_test1.png')

Expand Down Expand Up @@ -549,21 +545,13 @@ def test_rendering_maximum_data(self):
self.assertContains(response, '<a class="logo" href="http://test_site.localhost">')
# Test an item from course info
self.assertContains(response, 'course_title_0')
# Test an item from course description
self.assertContains(response, 'course_description_0')
# Test an item from user info
self.assertContains(response, f"{self.user.profile.name}, you earned a certificate!")
# Test an item from social info
self.assertContains(response, "Post on Facebook")
self.assertContains(response, "Share on Twitter")
# Test an item from certificate/org info
self.assertContains(
response,
"a course of study offered by {partner_short_name}, "
"an online learning initiative of "
"{partner_long_name}.".format(
partner_short_name=short_org_name,
partner_long_name=long_org_name,
),
)
# Test item from badge info
self.assertContains(response, "Add to Mozilla Backpack")
# Test item from site configuration
Expand Down
5 changes: 4 additions & 1 deletion lms/djangoapps/certificates/views/webview.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,10 @@ def _update_course_context(request, context, course, platform_name):
course_number = course.display_coursenumber if course.display_coursenumber else course.number
context['course_number'] = course_number
context['idv_enabled_for_certificates'] = settings.FEATURES.get('ENABLE_CERTIFICATES_IDV_REQUIREMENT')
if context['organization_long_name']:
course_description_override = context['certificate_data'].get('course_description', '')
if course_description_override:
context['accomplishment_copy_course_description'] = course_description_override
elif context['organization_long_name']:
# Translators: This text represents the description of course
context['accomplishment_copy_course_description'] = _('a course of study offered by {partner_short_name}, '
'an online learning initiative of '
Expand Down

0 comments on commit 613d845

Please sign in to comment.