def update_course_enrollment(username, course_id, mode=None, is_active=None):
 course_key = CourseKey.from_string(course_id)
 try:
  user = User.objects.get(username=username)
 except User.DoesNotExist:
  msg = u"Not user with username '{username}' found.".format(username=username)
  log.warn(msg)
  raise UserNotFoundError(msg)
 try:
  enrollment = CourseEnrollment.objects.get(user=user, course_id=course_key)
  return _update_enrollment(enrollment, is_active=is_active, mode=mode)
 except CourseEnrollment.DoesNotExist:
  return None

def update_course_enrollment ( username , course_id , mode = None , is_active = None ) : course_key = CourseKey . from_string ( course_id ) try : user = User . objects . get ( username = username ) except User . DoesNotExist : msg = u"Not user with username '{username}' found." . format ( username = username ) log . warn ( msg ) raise UserNotFoundError ( msg ) try : enrollment = CourseEnrollment . objects . get ( user = user , course_id = course_key ) return _update_enrollment ( enrollment , is_active = is_active , mode = mode ) except CourseEnrollment . DoesNotExist : return None
modify a course enrollment for a user .