def get_course_enrollment_info(course_id, include_expired=False): """Returns all course enrollment information for the given course. Based on the course id, return all related course information.. Args: course_id (str): The course to retrieve enrollment information for. include_expired (bool): Boolean denoting whether expired course modes should be included in the returned JSON data. Returns: A serializable dictionary representing the course's enrollment information. Raises: CourseNotFoundError """ course_key = CourseKey.from_string(course_id) course = modulestore().get_course(course_key) if course is None: msg = u"Requested enrollment information for unknown course {course}".format(course=course_id) log.warning(msg) raise CourseNotFoundError(msg) return CourseField().to_native(course, include_expired=include_expired)
def get_course_enrollment_info(course_id, include_expired=False): """Returns all course enrollment information for the given course. Based on the course id, return all related course information. Args: course_id (str): The course to retrieve enrollment information for. include_expired (bool): Boolean denoting whether expired course modes should be included in the returned JSON data. Returns: A serializable dictionary representing the course's enrollment information. Raises: CourseNotFoundError """ course_key = CourseKey.from_string(course_id) try: course = CourseOverview.get_from_id(course_key) except CourseOverview.DoesNotExist: msg = u"Requested enrollment information for unknown course {course}".format( course=course_id) log.warning(msg) raise CourseNotFoundError(msg) else: return CourseSerializer(course, include_expired=include_expired).data
def create_course_enrollment(username, course_id, mode, is_active): """Create a new course enrollment for the given user. Creates a new course enrollment for the specified user username. Args: username (str): The name of the user to create a new course enrollment for. course_id (str): The course to create the course enrollment for. mode (str): (Optional) The mode for the new enrollment. is_active (boolean): (Optional) Determines if the enrollment is active. Returns: A serializable dictionary representing the new course enrollment. Raises: CourseNotFoundError CourseEnrollmentFullError EnrollmentClosedError CourseEnrollmentExistsError """ 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.enroll(user, course_key, check_access=True) return _update_enrollment(enrollment, is_active=is_active, mode=mode) except NonExistentCourseError as err: raise CourseNotFoundError(err.message) except EnrollmentClosedError as err: raise CourseEnrollmentClosedError(err.message) except CourseFullError as err: raise CourseEnrollmentFullError(err.message) except AlreadyEnrolledError as err: enrollment = get_course_enrollment(username, course_id) raise CourseEnrollmentExistsError(err.message, enrollment)
def get_course_enrollment_info(course_id): """Returns all course enrollment information for the given course. Based on the course id, return all related course information.. Args: course_id (str): The course to retrieve enrollment information for. Returns: A serializable dictionary representing the course's enrollment information. Raises: CourseNotFoundError """ course_key = CourseKey.from_string(course_id) course = modulestore().get_course(course_key) if course is None: msg = u"Requested enrollment information for unknown course {course}".format( course=course_id) log.warning(msg) raise CourseNotFoundError(msg) return CourseField().to_native(course)