openedx.features.enterprise_support.enrollments package#

Submodules#

openedx.features.enterprise_support.enrollments.exceptions module#

exception openedx.features.enterprise_support.enrollments.exceptions.CourseIdMissingException#

Bases: Exception

course_id missing

exception openedx.features.enterprise_support.enrollments.exceptions.UserDoesNotExistException#

Bases: Exception

course_id invalid

openedx.features.enterprise_support.enrollments.utils module#

Utils for use in enrollment codebase such as views.

openedx.features.enterprise_support.enrollments.utils.lms_update_or_create_enrollment(username, course_id, desired_mode, is_active, enterprise_uuid=None, force_enrollment=False)#

Update or create the user’s course enrollment based on the existing enrollment mode. If an enrollment exists and its mode is not equal to the desired mode, then it updates the enrollment. Otherwise, it creates a new enrollment. Enrollment function meant to be called by edx-enterprise to replace the current uses of the EnrollmentApiClient The REST enrollment endpoint may also eventually also want to reuse this function since it’s a subset of what the endpoint handles

Unlike the REST endpoint, this function does not check for enterprise enabled, or user api key permissions etc. Those concerns are still going to be used by REST endpoint but this function is meant for use from within edx-enterprise hence already presume such privileges.

Parameters:
  • username (-) – User name

  • course_id (-) – Course key obtained using CourseKey.from_string(course_id_input)

  • desired_mode (-) – desired course mode

  • is_active (-) – A Boolean value that indicates whether the enrollment is to be set to inactive (if False). Usually we want a True if enrolling anew.

  • enterprise_uuid (-) – Optional. id to identify the enterprise to enroll under

  • force_enrollment (-) – Enroll user even if course enrollment_end date is expired (default False). This only has an effect when the enrollment is being created, not when it is only updated.

Returns: A serializable dictionary of the new or updated course enrollment. If it hits

CourseEnrollmentError or CourseEnrollmentNotUpdatableError, it raises those exceptions. In case of the add_enrollment call, it returns None if the enrollment already exists and the desired_mode or is_active match the existing enrollment.

Module contents#