openedx.core.djangoapps.enrollments package#
Subpackages#
Submodules#
openedx.core.djangoapps.enrollments.api module#
Enrollment API for creating, updating, and deleting enrollments. Also provides access to enrollment information at a course level, such as available course modes.
- openedx.core.djangoapps.enrollments.api.add_enrollment(username, course_id, mode=None, is_active=True, enrollment_attributes=None, enterprise_uuid=None, force_enrollment=False, include_expired=False)#
Enrolls a user in a course.
Enrolls a user in a course. If the mode is not specified, this will default to CourseMode.DEFAULT_MODE_SLUG.
- Parameters:
username – The user to enroll.
course_id (str) – The course to enroll the user in.
mode (str) – Optional argument for the type of enrollment to create. Ex. ‘audit’, ‘honor’, ‘verified’, ‘professional’. If not specified, this defaults to the default course mode.
is_active (boolean) – Optional argument for making the new enrollment inactive. If not specified, is_active defaults to True.
enrollment_attributes (list) – Attributes to be set the enrollment.
enterprise_uuid (str) – Add course enterprise uuid
force_enrollment (bool) – Enroll user even if course enrollment_end date is expired
include_expired (bool) – Boolean denoting whether expired course modes should be included.
- Returns:
A serializable dictionary of the new course enrollment.
Example
>>> add_enrollment("Bob", "edX/DemoX/2014T2", mode="audit") { "created": "2014-10-20T20:18:00Z", "mode": "audit", "is_active": True, "user": "Bob", "course_details": { "course_id": "edX/DemoX/2014T2", "course_name": "edX Demonstration Course", "enrollment_end": "2014-12-20T20:18:00Z", "enrollment_start": "2014-10-15T20:18:00Z", "course_start": "2015-02-03T00:00:00Z", "course_end": "2015-05-06T00:00:00Z", "course_modes": [ { "slug": "audit", "name": "Audit", "min_price": 0, "suggested_prices": "", "currency": "usd", "expiration_datetime": null, "description": null, "sku": null, "bulk_sku": null } ], "invite_only": False } }
- openedx.core.djangoapps.enrollments.api.get_course_enrollment_details(course_id, include_expired=False)#
Get the course modes for course. Also get enrollment start and end date, invite only, etc.
Given a course_id, return a serializable dictionary of properties describing course enrollment information.
- Parameters:
course_id (str) – The Course to get enrollment information for.
include_expired (bool) – Boolean denoting whether expired course modes
data. (should be included in the returned JSON)
- Returns:
A serializable dictionary of course enrollment information.
Example
>>> get_course_enrollment_details("edX/DemoX/2014T2") { "course_id": "edX/DemoX/2014T2", "course_name": "edX Demonstration Course", "enrollment_end": "2014-12-20T20:18:00Z", "enrollment_start": "2014-10-15T20:18:00Z", "course_start": "2015-02-03T00:00:00Z", "course_end": "2015-05-06T00:00:00Z", "course_modes": [ { "slug": "honor", "name": "Honor Code Certificate", "min_price": 0, "suggested_prices": "", "currency": "usd", "expiration_datetime": null, "description": null, "sku": null, "bulk_sku": null } ], "invite_only": False }
- openedx.core.djangoapps.enrollments.api.get_enrollment(username, course_id)#
Retrieves all enrollment information for the user in respect to a specific course.
Gets all the course enrollment information specific to a user in a course.
- Parameters:
username – The user to get course enrollment information for.
course_id (str) – The course to get enrollment information for.
- Returns:
A serializable dictionary of the course enrollment.
Example
>>> get_enrollment("Bob", "edX/DemoX/2014T2") { "created": "2014-10-20T20:18:00Z", "mode": "honor", "is_active": True, "user": "Bob", "course_details": { "course_id": "edX/DemoX/2014T2", "course_name": "edX Demonstration Course", "enrollment_end": "2014-12-20T20:18:00Z", "enrollment_start": "2014-10-15T20:18:00Z", "course_start": "2015-02-03T00:00:00Z", "course_end": "2015-05-06T00:00:00Z", "course_modes": [ { "slug": "honor", "name": "Honor Code Certificate", "min_price": 0, "suggested_prices": "", "currency": "usd", "expiration_datetime": null, "description": null, "sku": null, "bulk_sku": null } ], "invite_only": False } }
- openedx.core.djangoapps.enrollments.api.get_enrollment_attributes(username, course_id)#
Retrieve enrollment attributes for given user for provided course.
- Parameters:
username – The User to get enrollment attributes for
course_id – The Course to get enrollment attributes for.
Example
>>>get_enrollment_attributes(“Bob”, “course-v1-edX-DemoX-1T2015”) [
- {
“namespace”: “credit”, “name”: “provider_id”, “value”: “hogwarts”,
},
]
Returns: list
- openedx.core.djangoapps.enrollments.api.get_enrollments(username, include_inactive=False)#
Retrieves all the courses a user is enrolled in.
Takes a user and retrieves all relative enrollments. Includes information regarding how the user is enrolled in the the course.
- Parameters:
username – The username of the user we want to retrieve course enrollment information for.
include_inactive (bool) – Determines whether inactive enrollments will be included
- Returns:
A list of enrollment information for the given user.
Examples
>>> get_enrollments("Bob") [ { "created": "2014-10-20T20:18:00Z", "mode": "honor", "is_active": True, "user": "Bob", "course_details": { "course_id": "edX/DemoX/2014T2", "course_name": "edX Demonstration Course", "enrollment_end": "2014-12-20T20:18:00Z", "enrollment_start": "2014-10-15T20:18:00Z", "course_start": "2015-02-03T00:00:00Z", "course_end": "2015-05-06T00:00:00Z", "course_modes": [ { "slug": "honor", "name": "Honor Code Certificate", "min_price": 0, "suggested_prices": "", "currency": "usd", "expiration_datetime": null, "description": null, "sku": null, "bulk_sku": null } ], "invite_only": False } }, { "created": "2014-10-25T20:18:00Z", "mode": "verified", "is_active": True, "user": "Bob", "course_details": { "course_id": "edX/edX-Insider/2014T2", "course_name": "edX Insider Course", "enrollment_end": "2014-12-20T20:18:00Z", "enrollment_start": "2014-10-15T20:18:00Z", "course_start": "2015-02-03T00:00:00Z", "course_end": "2015-05-06T00:00:00Z", "course_modes": [ { "slug": "honor", "name": "Honor Code Certificate", "min_price": 0, "suggested_prices": "", "currency": "usd", "expiration_datetime": null, "description": null, "sku": null, "bulk_sku": null } ], "invite_only": True } } ]
- openedx.core.djangoapps.enrollments.api.get_user_roles(username)#
Returns a list of all roles that this user has. :param username: The id of the selected user. :return: All roles for all courses that this user has.
- openedx.core.djangoapps.enrollments.api.get_verified_enrollments(username, include_inactive=False)#
Retrieves all the courses in which user is enrolled in a verified mode.
Takes a user and retrieves all relative enrollments in which the learner is enrolled in a verified mode. Includes information regarding how the user is enrolled in the the course.
- Parameters:
username – The username of the user we want to retrieve course enrollment information for.
include_inactive (bool) – Determines whether inactive enrollments will be included
- Returns:
A list of enrollment information for the given user.
Examples
>>> get_verified_enrollments("Bob") [ { "created": "2014-10-25T20:18:00Z", "mode": "verified", "is_active": True, "user": "Bob", "course_details": { "course_id": "edX/edX-Insider/2014T2", "course_name": "edX Insider Course", "enrollment_end": "2014-12-20T20:18:00Z", "enrollment_start": "2014-10-15T20:18:00Z", "course_start": "2015-02-03T00:00:00Z", "course_end": "2015-05-06T00:00:00Z", "course_modes": [ { "slug": "honor", "name": "Honor Code Certificate", "min_price": 0, "suggested_prices": "", "currency": "usd", "expiration_datetime": null, "description": null, "sku": null, "bulk_sku": null } ], "invite_only": True } } ]
- openedx.core.djangoapps.enrollments.api.is_enrollment_valid_for_proctoring(username, course_id)#
Returns a boolean value regarding whether user’s course enrollment is eligible for proctoring.
- Returns false if:
special exams aren’t enabled
the enrollment is not active
proctored exams aren’t enabled for the course
the course mode is audit
- Parameters:
username (*) – The user associated with the enrollment.
course_id (*) – The course id associated with the enrollment.
- openedx.core.djangoapps.enrollments.api.serialize_enrollments(enrollments)#
Takes a list of CourseEnrollment objects and serializes them.
Serialized result will be compatible will the results from get_enrollments. If the get_enrollments function changes to return non-serialized data, this will need to change as well.
- Parameters:
enrollments – list of CourseEnrollment objects to be serialized
- Returns:
A list of enrollments
- openedx.core.djangoapps.enrollments.api.set_enrollment_attributes(username, course_id, attributes)#
Set enrollment attributes for the enrollment of given user in the course provided.
- Parameters:
course_id – The Course to set enrollment attributes for.
username – The User to set enrollment attributes for.
attributes (list) – Attributes to be set.
Example
- >>>set_enrollment_attributes(
“Bob”, “course-v1-edX-DemoX-1T2015”, [
- {
“namespace”: “credit”, “name”: “provider_id”, “value”: “hogwarts”,
},
]
)
- openedx.core.djangoapps.enrollments.api.unenroll_user_from_all_courses(username)#
Unenrolls a specified user from all of the courses they are currently enrolled in. :param username: The id of the user being unenrolled. :return: The IDs of all of the organizations from which the learner was unenrolled.
- openedx.core.djangoapps.enrollments.api.update_enrollment(username, course_id, mode=None, is_active=None, enrollment_attributes=None, include_expired=False)#
Updates the course mode for the enrolled user.
Update a course enrollment for the given user and course.
- Parameters:
username – The user associated with the updated enrollment.
course_id (str) – The course associated with the updated enrollment.
- Keyword Arguments:
mode (str) – The new course mode for this enrollment.
is_active (bool) – Sets whether the enrollment is active or not.
enrollment_attributes (list) – Attributes to be set the enrollment.
include_expired (bool) – Boolean denoting whether expired course modes should be included.
- Returns:
A serializable dictionary representing the updated enrollment.
Example
>>> update_enrollment("Bob", "edX/DemoX/2014T2", "honor") { "created": "2014-10-20T20:18:00Z", "mode": "honor", "is_active": True, "user": "Bob", "course_details": { "course_id": "edX/DemoX/2014T2", "course_name": "edX Demonstration Course", "enrollment_end": "2014-12-20T20:18:00Z", "enrollment_start": "2014-10-15T20:18:00Z", "course_start": "2015-02-03T00:00:00Z", "course_end": "2015-05-06T00:00:00Z", "course_modes": [ { "slug": "honor", "name": "Honor Code Certificate", "min_price": 0, "suggested_prices": "", "currency": "usd", "expiration_datetime": null, "description": null, "sku": null, "bulk_sku": null } ], "invite_only": False } }
- openedx.core.djangoapps.enrollments.api.validate_course_mode(course_id, mode, is_active=None, include_expired=False)#
Checks to see if the specified course mode is valid for the course.
If the requested course mode is not available for the course, raise an error with corresponding course enrollment information.
- Parameters:
course_id (str) – The course to check against for available course modes.
mode (str) – The slug for the course mode specified in the enrollment.
- Keyword Arguments:
is_active (bool) – Whether the enrollment is to be activated or deactivated.
include_expired (bool) – Boolean denoting whether expired course modes should be included.
- Returns:
None
- Raises:
CourseModeNotFound – raised if the course mode is not found.
openedx.core.djangoapps.enrollments.apps module#
Enrollments Application Configuration
Signal handlers are connected here.
openedx.core.djangoapps.enrollments.data module#
Data Aggregation Layer of the Enrollment API. Collects all enrollment specific data into a single source to be used throughout the API.
- openedx.core.djangoapps.enrollments.data.add_or_update_enrollment_attr(username, course_id, attributes)#
Set enrollment attributes for the enrollment of given user in the course provided.
- Parameters:
course_id (str) – The Course to set enrollment attributes for.
username – The User to set enrollment attributes for.
attributes (list) – Attributes to be set.
Example
- >>>add_or_update_enrollment_attr(
“Bob”, “course-v1-edX-DemoX-1T2015”, [
- {
“namespace”: “credit”, “name”: “provider_id”, “value”: “hogwarts”,
},
]
)
- openedx.core.djangoapps.enrollments.data.create_course_enrollment(username, course_id, mode, is_active, enterprise_uuid=None, force_enrollment=False)#
Create a new course enrollment for the given user.
Creates a new course enrollment for the specified user username.
- Parameters:
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.
enterprise_uuid (str) – Add course enterprise uuid
force_enrollment (bool) – Enroll user even if course enrollment_end date is expired
- Returns:
A serializable dictionary representing the new course enrollment.
- Raises:
EnrollmentClosedError –
- openedx.core.djangoapps.enrollments.data.get_course_enrollment(username, course_id)#
Retrieve an object representing all aggregated data for a user’s course enrollment.
Get the course enrollment information for a specific user and course.
- Parameters:
username (str) – The name of the user to retrieve course enrollment information for.
course_id (str) – The course to retrieve course enrollment information for.
- Returns:
A serializable dictionary representing the course enrollment.
- openedx.core.djangoapps.enrollments.data.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.
- Parameters:
course_id (str) – The course to retrieve enrollment information for.
include_expired (bool) – Boolean denoting whether expired course modes
data. (should be included in the returned JSON)
- Returns:
A serializable dictionary representing the course’s enrollment information.
- Raises:
- openedx.core.djangoapps.enrollments.data.get_course_enrollments(username, include_inactive=False)#
Retrieve a list representing all aggregated data for a user’s course enrollments.
Construct a representation of all course enrollment data for a specific user.
- Parameters:
username – The name of the user to retrieve course enrollment information for.
include_inactive (bool) – Determines whether inactive enrollments will be included
- Returns:
A serializable list of dictionaries of all aggregated enrollment data for a user.
- openedx.core.djangoapps.enrollments.data.get_enrollment_attributes(username, course_id)#
Retrieve enrollment attributes for given user for provided course.
- Parameters:
username – The User to get enrollment attributes for
course_id (str) – The Course to get enrollment attributes for.
Example
>>>get_enrollment_attributes(“Bob”, “course-v1-edX-DemoX-1T2015”) [
- {
“namespace”: “credit”, “name”: “provider_id”, “value”: “hogwarts”,
},
]
Returns: list
- openedx.core.djangoapps.enrollments.data.get_user_enrollments(course_key)#
Based on the course id, return all user enrollments in the course :param course_key: Identifier of the course :type course_key: CourseKey :param from which to retrieve enrollments.:
- Returns:
A course’s user enrollments as a queryset
- Raises:
CourseEnrollment.DoesNotExist –
- openedx.core.djangoapps.enrollments.data.get_user_roles(username)#
Returns a set of all roles that this user has. :param username: The id of the selected user. :return: All roles for all courses that this user has.
- openedx.core.djangoapps.enrollments.data.serialize_enrollments(enrollments)#
Take CourseEnrollment objects and return them in a serialized list.
- openedx.core.djangoapps.enrollments.data.unenroll_user_from_all_courses(username)#
Set all of a user’s enrollments to inactive. :param username: The user being unenrolled. :return: A list of all courses from which the user was unenrolled.
- openedx.core.djangoapps.enrollments.data.update_course_enrollment(username, course_id, mode=None, is_active=None)#
Modify a course enrollment for a user.
Allows updates to a specific course enrollment.
- Parameters:
username (str) – The name of the user to retrieve course enrollment information for.
course_id (str) – The course to retrieve course enrollment information for.
mode (str) – (Optional) If specified, modify the mode for this enrollment.
is_active (boolean) – (Optional) Determines if the enrollment is active.
- Returns:
A serializable dictionary representing the modified course enrollment.
openedx.core.djangoapps.enrollments.enrollments_notifications module#
Enrollment notifications sender util.
- class openedx.core.djangoapps.enrollments.enrollments_notifications.EnrollmentNotificationSender(course, user_id, audit_access_expiry)#
Bases:
objectClass to send notifications to user about their enrollments.
- send_audit_access_expiring_soon_notification()#
Send audit access expiring soon notification to user
openedx.core.djangoapps.enrollments.errors module#
All Error Types pertaining to Enrollment.
- exception openedx.core.djangoapps.enrollments.errors.CourseEnrollmentClosedError(msg, data=None)#
Bases:
CourseEnrollmentError
- exception openedx.core.djangoapps.enrollments.errors.CourseEnrollmentError(msg, data=None)#
Bases:
ExceptionGeneric Course Enrollment Error.
Describes any error that may occur when reading or updating enrollment information for a user or a course.
- exception openedx.core.djangoapps.enrollments.errors.CourseEnrollmentExistsError(message, enrollment)#
Bases:
CourseEnrollmentError- enrollment = None#
- exception openedx.core.djangoapps.enrollments.errors.CourseEnrollmentFullError(msg, data=None)#
Bases:
CourseEnrollmentError
- exception openedx.core.djangoapps.enrollments.errors.CourseEnrollmentNotUpdatableError(msg, data=None)#
Bases:
CourseEnrollmentErrorThe requested enrollment could not be updated.
- exception openedx.core.djangoapps.enrollments.errors.CourseModeNotFoundError(msg, data=None)#
Bases:
CourseEnrollmentErrorThe requested course mode could not be found.
- exception openedx.core.djangoapps.enrollments.errors.EnrollmentApiLoadError(msg, data=None)#
Bases:
CourseEnrollmentErrorThe data API could not be loaded.
- exception openedx.core.djangoapps.enrollments.errors.EnrollmentNotFoundError(msg, data=None)#
Bases:
CourseEnrollmentErrorThe requested enrollment could not be found.
- exception openedx.core.djangoapps.enrollments.errors.InvalidEnrollmentAttribute(msg, data=None)#
Bases:
CourseEnrollmentErrorEnrollment Attributes could not be validated
- exception openedx.core.djangoapps.enrollments.errors.UserNotFoundError(msg, data=None)#
Bases:
CourseEnrollmentError
openedx.core.djangoapps.enrollments.forms module#
Forms for validating user input to the Course Enrollment related views.
- class openedx.core.djangoapps.enrollments.forms.CourseEnrollmentsApiListForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None, bound_field_class=None)#
Bases:
FormA form that validates the query string parameters for the CourseEnrollmentsApiListView.
- MAX_INPUT_COUNT = 100#
- base_fields = {'course_id': <django.forms.fields.CharField object>, 'course_ids': <django.forms.fields.CharField object>, 'email': <django.forms.fields.CharField object>, 'username': <django.forms.fields.CharField object>}#
- clean_course_id()#
Validate and return a course ID.
- clean_course_ids()#
Validate a string of comma-separated course IDs and return a list of course IDs.
- clean_email()#
Validate a string of comma-separated emails and return a list of emails.
- clean_username()#
Validate a string of comma-separated usernames and return a list of usernames.
- declared_fields = {'course_id': <django.forms.fields.CharField object>, 'course_ids': <django.forms.fields.CharField object>, 'email': <django.forms.fields.CharField object>, 'username': <django.forms.fields.CharField object>}#
- property media#
Return all media required to render the widgets on this form.
openedx.core.djangoapps.enrollments.paginators module#
Paginators for the course enrollment related views.
openedx.core.djangoapps.enrollments.permissions module#
Permission definitions for the enrollments djangoapp
openedx.core.djangoapps.enrollments.serializers module#
Serializers for all Course Enrollment related return objects.
- class openedx.core.djangoapps.enrollments.serializers.CourseEnrollmentAllowedSerializer(*args, **kwargs)#
Bases:
ModelSerializerSerializes CourseEnrollmentAllowed model
Aggregates all data from the CourseEnrollmentAllowed table, and pulls in the serialization to give a complete representation of course enrollment allowed.
- class openedx.core.djangoapps.enrollments.serializers.CourseEnrollmentSerializer(*args, **kwargs)#
Bases:
ModelSerializerSerializes CourseEnrollment models
Aggregates all data from the Course Enrollment table, and pulls in the serialization for the Course block and course modes, to give a complete representation of course enrollment.
- class Meta#
Bases:
object- fields = ('created', 'mode', 'is_active', 'course_details', 'user')#
- lookup_field = 'username'#
- model#
alias of
CourseEnrollment
- get_username(model)#
Retrieves the username from the associated model.
- class openedx.core.djangoapps.enrollments.serializers.CourseEnrollmentsApiListSerializer(*args, **kwargs)#
Bases:
CourseEnrollmentSerializerSerializes CourseEnrollment model and returns a subset of fields returned by the CourseEnrollmentSerializer.
- class openedx.core.djangoapps.enrollments.serializers.CourseSerializer(*args, **kwargs)#
Bases:
SerializerSerialize a course block and related information.
- get_course_modes(obj)#
Retrieve course modes associated with the course.
- get_pacing_type(obj)#
Get a string representation of the course pacing.
- class openedx.core.djangoapps.enrollments.serializers.ModeSerializer(*args, **kwargs)#
Bases:
SerializerSerializes a course’s ‘Mode’ tuples
Returns a serialized representation of the modes available for course enrollment. The course modes models are designed to return a tuple instead of the model object itself. This serializer does not handle the model object itself, but the tuple.
- class openedx.core.djangoapps.enrollments.serializers.StringListField(*args, **kwargs)#
Bases:
CharFieldCustom Serializer for turning a comma delimited string into a list.
This field is designed to take a string such as “1,2,3” and turn it into an actual list [1,2,3]
- field_to_native(obj, field_name)#
Serialize the object’s class name.
openedx.core.djangoapps.enrollments.services module#
Enrollments Service
- class openedx.core.djangoapps.enrollments.services.EnrollmentsService#
Bases:
objectEnrollments service
Provides functions related to course enrollments
- get_active_enrollments_by_course(course_id)#
Returns a list of active enrollments for a course
- get_active_enrollments_by_course_and_user(course_id, user_id)#
Returns a list of active enrollments for a course and user.
Parameters: * course_id: course ID for the course * user_id: ID of User object
- get_enrollments_can_take_proctored_exams(course_id, text_search=None)#
Return all enrollments for a course that are in a mode that makes the corresponding user eligible to take proctored exams.
NOTE: Due to performance concerns, this method returns a QuerySet. Ordinarily, model implementations should not be exposed to clients in this way. However, the clients may need to do additional computation in the database to avoid performance penalties.
Parameters: * course_id: course ID for the course * text_search: the string against which to do a match on users’ username or email; optional
openedx.core.djangoapps.enrollments.urls module#
URLs for the Enrollment API
openedx.core.djangoapps.enrollments.views module#
The Enrollment API Views should be simple, lean HTTP endpoints for API access. This should consist primarily of authentication, request validation, and serialization.
- class openedx.core.djangoapps.enrollments.views.ApiKeyPermissionMixIn#
Bases:
objectThis mixin is used to provide a convenience function for doing individual permission checks for the presence of API keys.
- has_api_key_permissions(request)#
Checks to see if the request was made by a server with an API key.
- Parameters:
request (Request) – the request being made into the view
- Returns:
True if the request has been made with a valid API key False otherwise
- class openedx.core.djangoapps.enrollments.views.CourseEnrollmentsApiListView(**kwargs)#
Bases:
DeveloperErrorViewMixin,ListAPIViewUse Cases
Get a list of all course enrollments, optionally filtered by a course ID or list of usernames.
Example Requests
GET /api/enrollment/v1/enrollments
GET /api/enrollment/v1/enrollments?course_id={course_id}
GET /api/enrollment/v1/enrollments?course_ids={course_id},{course_id},{course_id}
GET /api/enrollment/v1/enrollments?username={username},{username},{username}
GET /api/enrollment/v1/enrollments?course_id={course_id}&username={username}
GET /api/enrollment/v1/enrollments?email={email},{email}
Query Parameters for GET
course_id: Filters the result to course enrollments for the course corresponding to the given course ID. The value must be URL encoded. Optional.
course_ids: List of comma-separated course IDs. Filters the result to course enrollments for the courses corresponding to the given course IDs. Course IDs could be course run IDs or course IDs. The value must be URL encoded. Optional.
username: List of comma-separated usernames. Filters the result to the course enrollments of the given users. Optional.
email: List of comma-separated emails. Filters the result to the course enrollments of the given users. Optional.
page_size: Number of results to return per page. Optional.
page: Page number to retrieve. Optional.
Response Values
If the request for information about the course enrollments is successful, an HTTP 200 “OK” response is returned.
The HTTP 200 response has the following values.
results: A list of the course enrollments matching the request.
created: Date and time when the course enrollment was created.
mode: Mode for the course enrollment.
is_active: Whether the course enrollment is active or not.
user: Username of the user in the course enrollment.
course_id: Course ID of the course in the course enrollment.
next: The URL to the next page of results, or null if this is the last page.
previous: The URL to the next page of results, or null if this is the first page.
If the user is not logged in, a 401 error is returned.
If the user is not global staff, a 403 error is returned.
If the specified course_id is not valid or any of the specified usernames are not valid, a 400 error is returned.
If the specified course_id does not correspond to a valid course or if all the specified usernames do not correspond to valid users, an HTTP 200 “OK” response is returned with an empty ‘results’ field.
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
- check_throttles(request)#
Check if request should be throttled. Raises an appropriate exception if the request is throttled.
- get_queryset()#
Get all the course enrollments for the given course_id and/or given list of usernames.
- pagination_class#
alias of
CourseEnrollmentsApiListPagination
- permission_classes = (<class 'rest_framework.permissions.IsAdminUser'>,)#
- serializer_class#
alias of
CourseEnrollmentsApiListSerializer
- throttle_classes = (<class 'openedx.core.djangoapps.enrollments.views.EnrollmentUserThrottle'>,)#
- class openedx.core.djangoapps.enrollments.views.EnrollmentAllowedView(**kwargs)#
Bases:
APIViewA view that allows the retrieval and creation of enrollment allowed for a given user email and course id.
- check_required_data(request)#
Check if the request has email and course_id.
- delete(request)#
Deletes an enrollment allowed for a given user email and course id.
Example Request
DELETE /api/enrollment/v1/enrollment_allowed/
Note: The URL for this request must finish with /
Example request data: ``` {
“email”: “user@example.com”, “course_id”: “course-v1:edX+DemoX+Demo_Course”
}#
Parameters
email (required, string, _body_)
course_id (required, string, _body_)
Responses - 204: Enrollment allowed deleted. - 400: Bad request, missing data. - 403: Forbidden, you need to be staff. - 404: Not found, the course enrollment allowed doesn’t exists.
- get(request)#
Returns the enrollments allowed for a given user email.
Example Requests
GET /api/enrollment/v1/enrollment_allowed?email=user@example.com
Parameters
email (optional, string, _query_params_) - defaults to the calling user if not provided.
Responses - 200: Success. - 403: Forbidden, you need to be staff.
- permission_classes = (<class 'rest_framework.permissions.IsAdminUser'>,)#
- post(request)#
Creates an enrollment allowed for a given user email and course id.
Example Request
POST /api/enrollment/v1/enrollment_allowed/
Note: The URL for this request must finish with /
Example request data: ``` {
“email”: “user@example.com”, “course_id”: “course-v1:edX+DemoX+Demo_Course”, “auto_enroll”: true
}#
Parameters
email (required, string, _body_)
course_id (required, string, _body_)
auto_enroll (optional, bool: default=false, _body_)
Responses - 400: Bad request, missing data. - 403: Forbidden, you need to be staff. - 409: Conflict, enrollment allowed already exists.
- serializer_class#
alias of
CourseEnrollmentAllowedSerializer
- throttle_classes = (<class 'openedx.core.djangoapps.enrollments.views.EnrollmentUserThrottle'>,)#
- class openedx.core.djangoapps.enrollments.views.EnrollmentCourseDetailView(**kwargs)#
Bases:
APIViewUse Case
Get enrollment details for a course.
Response values include the course schedule and enrollment modes supported by the course. Use the parameter include_expired=1 to include expired enrollment modes in the response.
Note: Getting enrollment details for a course does not require authentication.
Example Requests
GET /api/enrollment/v1/course/{course_id}
GET /api/enrollment/v1/course/{course_id}?include_expired=1
Response Values
If the request is successful, an HTTP 200 “OK” response is returned along with a collection of course enrollments for the user or for the newly created enrollment.
Each course enrollment contains the following values.
course_end: The date and time when the course closes. If null, the course never ends.
course_id: The unique identifier for the course.
course_name: The name of the course.
course_modes: An array of data about the enrollment modes supported for the course. If the request uses the parameter include_expired=1, the array also includes expired enrollment modes.
Each enrollment mode collection includes the following values.
currency: The currency of the listed prices.
description: A description of this mode.
expiration_datetime: The date and time after which users cannot enroll in the course in this mode.
min_price: The minimum price for which a user can enroll in this mode.
name: The full name of the enrollment mode.
slug: The short name for the enrollment mode.
suggested_prices: A list of suggested prices for this enrollment mode.
course_start: The date and time when the course opens. If null, the course opens immediately when it is created.
enrollment_end: The date and time after which users cannot enroll for the course. If null, the enrollment period never ends.
enrollment_start: The date and time when users can begin enrolling in the course. If null, enrollment opens immediately when the course is created.
invite_only: A value indicating whether students must be invited to enroll in the course. Possible values are true or false.
- authentication_classes = []#
- check_throttles(request)#
Check if request should be throttled. Raises an appropriate exception if the request is throttled.
- get(request, course_id=None)#
Read enrollment information for a particular course.
HTTP Endpoint for retrieving course level enrollment information.
- Parameters:
request (Request) – To get current course enrollment information, a GET request will return information for the specified course.
course_id (str) – URI element specifying the course location. Enrollment information will be returned.
- Returns:
A JSON serialized representation of the course enrollment details.
- permission_classes = []#
- throttle_classes = (<class 'openedx.core.djangoapps.enrollments.views.EnrollmentUserThrottle'>,)#
- class openedx.core.djangoapps.enrollments.views.EnrollmentCrossDomainSessionAuth#
Bases:
SessionAuthenticationAllowInactiveUser,SessionAuthenticationCrossDomainCsrfSession authentication that allows inactive users and cross-domain requests.
- class openedx.core.djangoapps.enrollments.views.EnrollmentListView(**kwargs)#
Bases:
APIView,ApiKeyPermissionMixInUse Cases
Get a list of all course enrollments for the currently signed in user.
Enroll the currently signed in user in a course.
Currently a user can use this command only to enroll the user in the default course mode. If this is not supported for the course, the request fails and returns the available modes.
This command can use a server-to-server call to enroll a user in other modes, such as “verified”, “professional”, or “credit”. If the mode is not supported for the course, the request will fail and return the available modes.
You can include other parameters as enrollment attributes for a specific course mode. For example, for credit mode, you can include the following parameters to specify the credit provider attribute.
namespace: credit
name: provider_id
value: institution_name
Example Requests
GET /api/enrollment/v1/enrollment
POST /api/enrollment/v1/enrollment {
“mode”: “credit”, “course_details”:{“course_id”: “edX/DemoX/Demo_Course”}, “enrollment_attributes”:[{“namespace”: “credit”,”name”: “provider_id”,”value”: “hogwarts”,},]
}
POST Parameters
A POST request can include the following parameters.
user: Optional. The username of the currently logged in user. You cannot use the command to enroll a different user.
mode: Optional. The course mode for the enrollment. Individual users cannot upgrade their enrollment mode from the default. Only server-to-server requests can enroll with other modes.
is_active: Optional. A Boolean value indicating whether the enrollment is active. Only server-to-server requests are allowed to deactivate an enrollment.
course details: A collection that includes the following information.
course_id: The unique identifier for the course.
email_opt_in: Optional. A Boolean value that indicates whether the user wants to receive email from the organization that runs this course.
enrollment_attributes: A dictionary that contains the following values.
namespace: Namespace of the attribute
name: Name of the attribute
value: Value of the attribute
is_active: Optional. A Boolean value that indicates whether the enrollment is active. Only server-to-server requests can deactivate an enrollment.
mode: Optional. The course mode for the enrollment. Individual users cannot upgrade their enrollment mode from the default. Only server-to-server requests can enroll with other modes.
user: Optional. The user ID of the currently logged in user. You cannot use the command to enroll a different user.
enterprise_course_consent: Optional. A Boolean value that indicates the consent status for an EnterpriseCourseEnrollment to be posted to the Enterprise service.
GET Response Values
If an unspecified error occurs when the user tries to obtain a learner’s enrollments, the request returns an HTTP 400 “Bad Request” response.
If the user does not have permission to view enrollment data for the requested learner, the request returns an HTTP 404 “Not Found” response.
POST Response Values
If the user does not specify a course ID, the specified course does not exist, or the is_active status is invalid, the request returns an HTTP 400 “Bad Request” response.
If a user who is not an admin tries to upgrade a learner’s course mode, the request returns an HTTP 403 “Forbidden” response.
If the specified user does not exist, the request returns an HTTP 406 “Not Acceptable” response.
GET and POST Response Values
If the request is successful, an HTTP 200 “OK” response is returned along with a collection of course enrollments for the user or for the newly created enrollment.
Each course enrollment contains the following values.
course_details: A collection that includes the following values.
course_end: The date and time when the course closes. If null, the course never ends.
course_id: The unique identifier for the course.
course_name: The name of the course.
course_modes: An array of data about the enrollment modes supported for the course. If the request uses the parameter include_expired=1, the array also includes expired enrollment modes.
Each enrollment mode collection includes the following values.
currency: The currency of the listed prices.
description: A description of this mode.
expiration_datetime: The date and time after which users cannot enroll in the course in this mode.
min_price: The minimum price for which a user can enroll in this mode.
name: The full name of the enrollment mode.
slug: The short name for the enrollment mode.
suggested_prices: A list of suggested prices for this enrollment mode.
course_start: The date and time when the course opens. If null, the course opens immediately when it is created.
enrollment_end: The date and time after which users cannot enroll for the course. If null, the enrollment period never ends.
enrollment_start: The date and time when users can begin enrolling in the course. If null, enrollment opens immediately when the course is created.
invite_only: A value indicating whether students must be invited to enroll in the course. Possible values are true or false.
created: The date the user account was created.
is_active: Whether the enrollment is currently active.
mode: The enrollment mode of the user in this course.
user: The username of the user.
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'openedx.core.djangoapps.enrollments.views.EnrollmentCrossDomainSessionAuth'>)#
- check_throttles(request)#
Check if request should be throttled. Raises an appropriate exception if the request is throttled.
- get(request)#
Gets a list of all course enrollments for a user.
Returns a list for the currently logged in user, or for the user named by the ‘user’ GET parameter. If the username does not match that of the currently logged in user, only courses for which the currently logged in user has the Staff or Admin role are listed. As a result, a course team member can find out which of their own courses a particular learner is enrolled in.
Only the Staff or Admin role (granted on the Django administrative console as the staff or instructor permission) in individual courses gives the requesting user access to enrollment data. Permissions granted at the organizational level do not give a user access to enrollment data for all of that organization’s courses.
Users who have the global staff permission can access all enrollment data for all courses.
- permission_classes = (<class 'openedx.core.lib.api.permissions.ApiKeyHeaderPermissionIsAuthenticated'>,)#
- post(request)#
Enrolls the currently logged-in user in a course.
Server-to-server calls may deactivate or modify the mode of existing enrollments. All other requests go through add_enrollment(), which allows creation of new and reactivation of old enrollments.
- throttle_classes = (<class 'openedx.core.djangoapps.enrollments.views.EnrollmentUserThrottle'>,)#
- class openedx.core.djangoapps.enrollments.views.EnrollmentUserRolesView(**kwargs)#
Bases:
APIViewUse Case
Get the roles for the current logged-in user. A field is also included to indicate whether or not the user is a global staff member. If an optional course_id parameter is supplied, the returned roles will be filtered to only include roles for the given course.
Example Requests
GET /api/enrollment/v1/roles/?course_id={course_id}
course_id: (optional) A course id. The returned roles will be filtered to only include roles for the given course.
Response Values
If the request is successful, an HTTP 200 “OK” response is returned along with a collection of user roles for the logged-in user, filtered by course_id if given, along with whether or not the user is global staff
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'openedx.core.djangoapps.enrollments.views.EnrollmentCrossDomainSessionAuth'>)#
- get(request)#
Gets a list of all roles for the currently logged-in user, filtered by course_id if supplied
- permission_classes = (<class 'openedx.core.lib.api.permissions.ApiKeyHeaderPermissionIsAuthenticated'>,)#
- throttle_classes = (<class 'openedx.core.djangoapps.enrollments.views.EnrollmentUserThrottle'>,)#
- class openedx.core.djangoapps.enrollments.views.EnrollmentUserThrottle#
Bases:
UserRateThrottle,ApiKeyPermissionMixInLimit the number of requests users can make to the enrollment API.
- THROTTLE_RATES = {'staff': '120/minute', 'user': '40/minute'}#
- allow_request(request, view)#
Implement the check to see if the request should be throttled.
On success calls throttle_success. On failure calls throttle_failure.
- class openedx.core.djangoapps.enrollments.views.EnrollmentView(**kwargs)#
Bases:
APIView,ApiKeyPermissionMixInUse Case
Get the user’s enrollment status for a course.
Example Request
GET /api/enrollment/v1/enrollment/{username},{course_id}
Response Values
If the request for information about the user is successful, an HTTP 200 “OK” response is returned.
The HTTP 200 response has the following values.
course_details: A collection that includes the following values.
course_end: The date and time when the course closes. If null, the course never ends.
course_id: The unique identifier for the course.
course_name: The name of the course.
course_modes: An array of data about the enrollment modes supported for the course. If the request uses the parameter include_expired=1, the array also includes expired enrollment modes.
Each enrollment mode collection includes the following values.
currency: The currency of the listed prices.
description: A description of this mode.
expiration_datetime: The date and time after which users cannot enroll in the course in this mode.
min_price: The minimum price for which a user can enroll in this mode.
name: The full name of the enrollment mode.
slug: The short name for the enrollment mode.
suggested_prices: A list of suggested prices for this enrollment mode.
course_end: The date and time at which the course closes. If null, the course never ends.
course_start: The date and time when the course opens. If null, the course opens immediately when it is created.
enrollment_end: The date and time after which users cannot enroll for the course. If null, the enrollment period never ends.
enrollment_start: The date and time when users can begin enrolling in the course. If null, enrollment opens immediately when the course is created.
invite_only: A value indicating whether students must be invited to enroll in the course. Possible values are true or false.
created: The date the user account was created.
is_active: Whether the enrollment is currently active.
mode: The enrollment mode of the user in this course.
user: The ID of the user.
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
- check_throttles(request)#
Check if request should be throttled. Raises an appropriate exception if the request is throttled.
- get(request, course_id=None, username=None)#
Create, read, or update enrollment information for a user.
HTTP Endpoint for all CRUD operations for a user course enrollment. Allows creation, reading, and updates of the current enrollment for a particular course.
- Parameters:
request (Request) – To get current course enrollment information, a GET request will return information for the current user and the specified course.
course_id (str) – URI element specifying the course location. Enrollment information will be returned, created, or updated for this particular course.
username (str) – The username associated with this enrollment request.
- Returns:
A JSON serialized representation of the course enrollment.
- permission_classes = (<class 'openedx.core.lib.api.permissions.ApiKeyHeaderPermissionIsAuthenticated'>,)#
- throttle_classes = (<class 'openedx.core.djangoapps.enrollments.views.EnrollmentUserThrottle'>,)#
- class openedx.core.djangoapps.enrollments.views.UnenrollmentView(**kwargs)#
Bases:
APIViewUse Cases
Unenroll a single user from all courses.
This command can only be issued by a privileged service user.
Example Requests
- POST /api/enrollment/v1/enrollment {
“username”: “username12345”
}
POST Parameters
A POST request must include the following parameter.
username: The username of the user being unenrolled.
This will never match the username from the request, since the request is issued as a privileged service user.
POST Response Values
If the user has not requested retirement and does not have a retirement request status, the request returns an HTTP 404 “Does Not Exist” response.
If the user is already unenrolled from all courses, the request returns an HTTP 204 “No Content” response.
If an unexpected error occurs, the request returns an HTTP 500 response.
If the request is successful, an HTTP 200 “OK” response is returned along with a list of all courses from which the user was unenrolled.
- permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>, <class 'openedx.core.djangoapps.user_api.accounts.permissions.CanRetireUser'>)#
- post(request)#
Unenrolls the specified user from all courses.
Module contents#
Enrollment API helpers and settings