'Returns the CourseEnrollmentState for the given user
and course_key, caching the result for later retrieval.'

@classmethod
def _get_enrollment_state(cls, user, course_key):

    assert user
    if user.is_anonymous():
        return CourseEnrollmentState(None, None)
    enrollment_state = cls._get_enrollment_in_request_cache(user, course_key)
    if (not enrollment_state):
        try:
            record = cls.objects.get(user=user, course_id=course_key)
            enrollment_state = CourseEnrollmentState(record.mode, record.is_active)
        except cls.DoesNotExist:
            enrollment_state = CourseEnrollmentState(None, None)
        cls._update_enrollment_in_request_cache(user, course_key, enrollment_state)
    return enrollment_state
