Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BB-5819] Make course description editable in certs #29850

Closed
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
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 @@ -19,6 +19,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