Commit f98a27ef by Waheed Ahmed

Fix recent enrollment message and multiple donation boxes.

When purchasing multiple courses (especially with bundled Program purchase) the donation box shows up multiple times. Donation box should only show once regardless of number of courses purchased.

LEARNER-2125
parent 7c535f5f
......@@ -93,7 +93,7 @@ class TestRecentEnrollments(ModuleStoreTestCase, XssTestMixin):
"""
Test that the list of newly created courses are properly sorted to show the most
recent enrollments first.
Also test recent enrollment message rendered appropriately for more than two courses.
"""
self._configure_message_timeout(600)
......@@ -122,14 +122,61 @@ class TestRecentEnrollments(ModuleStoreTestCase, XssTestMixin):
self.assertEqual(recent_course_list[3].course.id, courses[2].id)
self.assertEqual(recent_course_list[4].course.id, courses[3].id)
def test_dashboard_rendering(self):
self.client.login(username=self.student.username, password=self.PASSWORD)
response = self.client.get(reverse("dashboard"))
# verify recent enrollment message
self.assertContains(
response,
'Thank you for enrolling in:'.format(course_name=self.course.display_name)
)
self.assertContains(
response,
', '.join(enrollment.course.display_name for enrollment in recent_course_list)
)
def test_dashboard_rendering_with_single_course(self):
"""
Tests that the dashboard renders the recent enrollment messages appropriately.
Tests that the dashboard renders the recent enrollment message appropriately for single course.
"""
self._configure_message_timeout(600)
self.client.login(username=self.student.username, password=self.PASSWORD)
response = self.client.get(reverse("dashboard"))
self.assertContains(response, "Thank you for enrolling in")
self.assertContains(
response,
"Thank you for enrolling in {course_name}".format(course_name=self.course.display_name)
)
def test_dashboard_rendering_with_two_courses(self):
"""
Tests that the dashboard renders the recent enrollment message appropriately for two courses.
"""
self._configure_message_timeout(600)
course_location = locator.CourseLocator(
'Org2',
'Course2',
'Run2'
)
course, _ = self._create_course_and_enrollment(course_location)
self.client.login(username=self.student.username, password=self.PASSWORD)
response = self.client.get(reverse("dashboard"))
courses_enrollments = list(get_course_enrollments(self.student, None, []))
courses_enrollments.sort(key=lambda x: x.created, reverse=True)
self.assertEqual(len(courses_enrollments), 3)
recent_course_enrollments = _get_recently_enrolled_courses(courses_enrollments)
self.assertEqual(len(recent_course_enrollments), 2)
self.assertContains(
response,
"Thank you for enrolling in:".format(course_name=self.course.display_name)
)
self.assertContains(
response,
' and '.join(enrollment.course.display_name for enrollment in recent_course_enrollments)
)
def test_dashboard_escaped_rendering(self):
"""
......
......@@ -933,20 +933,32 @@ def _create_recent_enrollment_message(course_enrollments, course_modes): # pyli
recently_enrolled_courses = _get_recently_enrolled_courses(course_enrollments)
if recently_enrolled_courses:
enroll_messages = [
{
"course_id": enrollment.course_overview.id,
"course_name": enrollment.course_overview.display_name,
"allow_donation": _allow_donation(course_modes, enrollment.course_overview.id, enrollment)
}
enrollments_count = len(recently_enrolled_courses)
course_name_separator = ', '
# If length of enrolled course 2, join names with 'and'
if enrollments_count == 2:
course_name_separator = _(' and ')
course_names = course_name_separator.join(
[enrollment.course_overview.display_name for enrollment in recently_enrolled_courses]
)
allow_donations = any(
_allow_donation(course_modes, enrollment.course_overview.id, enrollment)
for enrollment in recently_enrolled_courses
]
)
platform_name = configuration_helpers.get_value('platform_name', settings.PLATFORM_NAME)
return render_to_string(
'enrollment/course_enrollment_message.html',
{'course_enrollment_messages': enroll_messages, 'platform_name': platform_name}
{
'course_names': course_names,
'enrollments_count': enrollments_count,
'allow_donations': allow_donations,
'platform_name': platform_name,
'course_id': recently_enrolled_courses[0].course_overview.id if enrollments_count == 1 else None
}
)
......
<%! from django.utils.translation import ugettext as _ %>
<%page expression_filter="h"/>
% for course_msg in course_enrollment_messages:
<div class="wrapper-msg urgency-high">
<div class="wrapper-msg urgency-high">
<div class="msg has-actions">
<div class="msg-content donate-content">
<h2 class="sr">${_("Enrollment Successful")}</h2>
<div class="copy">
<p>${_("Thank you for enrolling in {enrolled_course}. We hope you enjoy the course.").format(enrolled_course=course_msg["course_name"])}</p>
% if course_msg["allow_donation"]:
% if enrollments_count == 1:
<p>${_("Thank you for enrolling in {course_names}. We hope you enjoy the course.").format(course_names=course_names)}</p>
% else:
<p>${_("Thank you for enrolling in:")}</p>
${course_names}
<p>${_("We hope you enjoy the course.")}</p>
% endif
% if allow_donations:
<p>
${_("{platform_name} is a nonprofit bringing high-quality education to everyone, everywhere. "
"Your help allows us to continuously improve the learning experience for millions and "
......@@ -16,12 +21,15 @@
% endif
</div>
</div>
% if course_msg["allow_donation"]:
% if allow_donations:
<div class="nav-actions donate-actions">
<h3 class="sr">${_('Donation Actions')}</h3>
<div class="donate-container" data-course="${ course_msg['course_id'] }"></div>
</div>
% if course_id:
<div class="donate-container" data-course="${ course_id }"></div>
% else:
<div class="donate-container"></div>
% endif
</div>
% endif
</div>
% endfor
</div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment