inactive enrollments in support tool

LEARNER-4744
This commit is contained in:
Tasawer Nawaz
2018-06-27 19:02:48 +05:00
parent 4b81ab6312
commit 8868f07394
6 changed files with 49 additions and 6 deletions

View File

@@ -18,7 +18,7 @@ log = logging.getLogger(__name__)
DEFAULT_DATA_API = 'enrollment.data'
def get_enrollments(user_id):
def get_enrollments(user_id, include_inactive=False):
"""Retrieves all the courses a user is enrolled in.
Takes a user and retrieves all relative enrollments. Includes information regarding how the user is enrolled
@@ -26,6 +26,7 @@ def get_enrollments(user_id):
Args:
user_id (str): The username of the user we want to retrieve course enrollment information for.
include_inactive (bool): Determines whether inactive enrollments will be included
Returns:
A list of enrollment information for the given user.
@@ -92,7 +93,7 @@ def get_enrollments(user_id):
]
"""
return _data_api().get_course_enrollments(user_id)
return _data_api().get_course_enrollments(user_id, include_inactive)
def get_enrollment(user_id, course_id):

View File

@@ -31,13 +31,15 @@ from student.models import (
log = logging.getLogger(__name__)
def get_course_enrollments(user_id):
def get_course_enrollments(user_id, include_inactive=False):
"""Retrieve a list representing all aggregated data for a user's course enrollments.
Construct a representation of all course enrollment data for a specific user.
Args:
user_id (str): The name of the user to retrieve course enrollment information for.
include_inactive (bool): Determines whether inactive enrollments will be included
Returns:
A serializable list of dictionaries of all aggregated enrollment data for a user.
@@ -45,9 +47,11 @@ def get_course_enrollments(user_id):
"""
qset = CourseEnrollment.objects.filter(
user__username=user_id,
is_active=True
).order_by('created')
if not include_inactive:
qset = qset.filter(is_active=True)
enrollments = CourseEnrollmentSerializer(qset, many=True).data
# Find deleted courses and filter them out of the results

View File

@@ -24,7 +24,7 @@ _VERIFIED_MODE_EXPIRED = []
# pylint: disable=unused-argument
def get_course_enrollments(student_id):
def get_course_enrollments(student_id, include_inactive=False):
"""Stubbed out Enrollment data request."""
return _ENROLLMENTS

View File

@@ -150,6 +150,42 @@ class EnrollmentDataTest(ModuleStoreTestCase):
updated_results = data.get_course_enrollments(self.user.username)
self.assertEqual(results, updated_results)
def test_get_enrollments_including_inactive(self):
""" Verify that if 'include_inactive' is True, all enrollments
are returned including inactive.
"""
course_modes, course_numbers = ['honor', 'verified', 'audit'], ['1', '2', '3']
created_courses = []
for course_number in course_numbers:
created_courses.append(CourseFactory.create(number=course_number))
created_enrollments = []
for course in created_courses:
self._create_course_modes(course_modes, course=course)
# Create the original enrollment.
created_enrollments.append(data.create_course_enrollment(
self.user.username,
unicode(course.id),
'honor',
True
))
# deactivate one enrollment
data.update_course_enrollment(
self.user.username,
unicode(created_courses[0].id),
'honor',
False
)
# by default in-active enrollment will be excluded.
results = data.get_course_enrollments(self.user.username)
self.assertNotEqual(len(results), len(created_enrollments))
# we can get all enrollments including inactive by passing "include_inactive"
results = data.get_course_enrollments(self.user.username, include_inactive=True)
self.assertEqual(len(results), len(created_enrollments))
@ddt.data(
# Default (no course modes in the database)
# Expect that users are automatically enrolled as "honor".

View File

@@ -27,6 +27,7 @@
<th><%- gettext('Verified mode price') %></th>
<th><%- gettext('Reason') %></th>
<th><%- gettext('Last modified by') %></th>
<th><%- gettext('Active') %></th>
<th></th>
</tr>
</thead>
@@ -43,6 +44,7 @@
<td><% print(enrollment.get('verified_price')) %></td>
<td><% print(enrollment.get('manual_enrollment').reason || gettext('N/A')) %></td>
<td><% print(enrollment.get('manual_enrollment').enrolled_by || gettext('N/A')) %></td>
<td><% print(enrollment.get('is_active')) %></td>
<td>
<button
class="change-enrollment-btn"

View File

@@ -62,7 +62,7 @@ class EnrollmentSupportListView(GenericAPIView):
except User.DoesNotExist:
return JsonResponse([])
enrollments = get_enrollments(user.username)
enrollments = get_enrollments(user.username, include_inactive=True)
for enrollment in enrollments:
# Folds the course_details field up into the main JSON object.
enrollment.update(**enrollment.pop('course_details'))