Commit ea1e875d by Chris Dodge

add ability to return the course name (optionally) when querying about credit…

add ability to return the course name (optionally) when querying about credit requirement fulfillments
parent 1f6d28e2
......@@ -10,6 +10,7 @@ from django.core.exceptions import ObjectDoesNotExist
from opaque_keys.edx.keys import CourseKey
from student.models import CourseEnrollment
from xmodule.modulestore.django import modulestore
log = logging.getLogger(__name__)
......@@ -47,7 +48,7 @@ class CreditService(object):
return is_credit_course(course_key)
def get_credit_state(self, user_id, course_key_or_id):
def get_credit_state(self, user_id, course_key_or_id, return_course_name=False):
"""
Return all information about the user's credit state inside of a given
course.
......@@ -64,6 +65,7 @@ class CreditService(object):
'profile_fullname': the name that the student registered under, used for verification
'is_credit_course': if the course has been marked as a credit bearing course
'credit_requirement_status': the user's status in fulfilling those requirements
'course_name': optional display name of the course
}
"""
......@@ -89,13 +91,20 @@ class CreditService(object):
# not enrolled
return None
return {
result = {
'enrollment_mode': enrollment.mode,
'profile_fullname': user.profile.name,
'is_credit_course': is_credit_course(course_key),
'credit_requirement_status': get_credit_requirement_status(course_key, user.username)
}
if return_course_name:
course = modulestore().get_course(course_key, depth=0)
result.update({
'course_name': course.display_name,
})
return result
def set_credit_requirement_status(self, user_id, course_key_or_id, req_namespace,
req_name, status="satisfied", reason=None):
"""
......
......@@ -121,6 +121,22 @@ class CreditServiceTests(ModuleStoreTestCase):
self.assertEqual(credit_state['credit_requirement_status'][0]['name'], 'grade')
self.assertEqual(credit_state['credit_requirement_status'][0]['status'], 'satisfied')
def test_course_name(self):
"""
Make sure we can get back the optional course name
"""
CourseEnrollment.enroll(self.user, self.course.id)
# make sure it is not returned by default
credit_state = self.service.get_credit_state(self.user.id, self.course.id)
self.assertNotIn('course_name', credit_state)
# now make sure it is in there when we pass in the flag
credit_state = self.service.get_credit_state(self.user.id, self.course.id, return_course_name=True)
self.assertIn('course_name', credit_state)
self.assertEqual(credit_state['course_name'], self.course.display_name)
def test_set_status_non_credit(self):
"""
assert that we can still try to update a credit status but return quickly if
......
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