lms.djangoapps.mobile_api.users package

Contents

lms.djangoapps.mobile_api.users package#

Submodules#

lms.djangoapps.mobile_api.users.enums module#

Enums for mobile_api users app.

class lms.djangoapps.mobile_api.users.enums.EnrollmentStatuses(*values)#

Bases: Enum

Enum for enrollment statuses.

ALL = 'all'#
COMPLETED = 'completed'#
EXPIRED = 'expired'#
IN_PROGRESS = 'in_progress'#
classmethod values()#

Returns string representation of all enum values.

lms.djangoapps.mobile_api.users.serializers module#

Serializer for user API

class lms.djangoapps.mobile_api.users.serializers.CourseEnrollmentSerializer(*args, **kwargs)#

Bases: ModelSerializer

Serializes CourseEnrollment models

class Meta#

Bases: object

fields = ('audit_access_expires', 'created', 'mode', 'is_active', 'course', 'certificate', 'course_modes')#
lookup_field = 'username'#
model#

alias of CourseEnrollment

get_audit_access_expires(model)#

Returns expiration date for a course audit expiration, if any or null

get_certificate(model)#

Returns the information about the user’s certificate in the course.

get_course_modes(obj)#

Retrieve course modes associated with the course.

to_representation(instance: CourseEnrollment) OrderedDict#

Override the to_representation method to add the course_status field to the serialized data.

class lms.djangoapps.mobile_api.users.serializers.CourseEnrollmentSerializerModifiedForPrimary(*args, **kwargs)#

Bases: CourseEnrollmentSerializer

Serializes CourseEnrollment models for API v4.

Adds course_status field into serializer data.

class Meta#

Bases: object

fields = ('audit_access_expires', 'created', 'mode', 'is_active', 'course', 'certificate', 'course_modes', 'course_status', 'course_progress', 'course_assignments')#
lookup_field = 'username'#
model#

alias of CourseEnrollment

get_course_assignments(model: CourseEnrollment) Dict[str, List[Dict[str, str]] | None]#

Returns the future assignment data and past assignments data for the user in the course.

get_course_progress(model: CourseEnrollment) Dict[str, int]#

Returns the progress of the user in the course.

get_course_status(model: CourseEnrollment) Dict[str, List[str]] | None#

Gets course status for the given user’s enrollments.

class lms.djangoapps.mobile_api.users.serializers.CourseEnrollmentSerializerv05(*args, **kwargs)#

Bases: CourseEnrollmentSerializer

Serializes CourseEnrollment models for v0.5 api Does not include ‘audit_access_expires’ field that is present in v1 api

class Meta#

Bases: object

fields = ('created', 'mode', 'is_active', 'course', 'certificate')#
lookup_field = 'username'#
model#

alias of CourseEnrollment

class lms.djangoapps.mobile_api.users.serializers.CourseOverviewField(*args, **kwargs)#

Bases: RelatedField

Custom field to wrap a CourseOverview object. Read-only.

to_representation(course_overview)#

Transform the outgoing native value into primitive data.

class lms.djangoapps.mobile_api.users.serializers.ModeSerializer(*args, **kwargs)#

Bases: Serializer

Serializes 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 handles the given tuple.

class lms.djangoapps.mobile_api.users.serializers.UserSerializer(*args, **kwargs)#

Bases: ModelSerializer

Serializes User models

class Meta#

Bases: object

fields = ('id', 'username', 'email', 'name', 'course_enrollments')#
lookup_field = 'username'#
model#

alias of User

ref_name = 'mobile_api.User'#
get_course_enrollments(model)#

lms.djangoapps.mobile_api.users.urls module#

URLs for user API

lms.djangoapps.mobile_api.users.views module#

Views for user API

class lms.djangoapps.mobile_api.users.views.UserCourseEnrollmentsList(**kwargs)#

Bases: ListAPIView

Use Case

Get information about the courses that the currently signed in user is enrolled in.

v1 differs from v0.5 version by returning ALL enrollments for a user rather than only the enrollments the user has access to (that haven’t expired). An additional attribute “expiration” has been added to the response, which lists the date when access to the course will expire or null if it doesn’t expire.

In v4 we added to the response primary object. Primary object contains the latest user’s enrollment or course where user has the latest progress. Primary object has been cut from user’s enrolments array and inserted into separated section with key primary.

Example Request

GET /api/mobile/v1/users/{username}/course_enrollments/

Response Values

If the request for information about the user is successful, the request returns an HTTP 200 “OK” response.

The HTTP 200 response has the following values.

  • expiration: The course expiration date for given user course pair or null if the course does not expire.

  • certificate: Information about the user’s earned certificate in the course.

  • course: A collection of the following data about the course.

  • courseware_access: A JSON representation with access information for the course, including any access errors.

    • course_about: The URL to the course about page.

    • course_sharing_utm_parameters: Encoded UTM parameters to be included in course sharing url

    • course_handouts: The URI to get data for course handouts.

    • course_image: The path to the course image.

    • course_updates: The URI to get data for course updates.

    • discussion_url: The URI to access data for course discussions if it is enabled, otherwise null.

    • end: The end date of the course.

    • id: The unique ID of the course.

    • name: The name of the course.

    • number: The course number.

    • org: The organization that created the course.

    • start: The date and time when the course starts.

    • start_display: If start_type is a string, then the advertised_start date for the course. If start_type is a timestamp, then a formatted date for the start of the course. If start_type is empty, then the value is None and it indicates that the course has not yet started.

    • start_type: One of either “string”, “timestamp”, or “empty”

    • subscription_id: A unique “clean” (alphanumeric with ‘_’) ID of the course.

    • video_outline: The URI to get the list of all videos that the user can access in the course.

  • created: The date the course was created.

  • is_active: Whether the course is currently active. Possible values are true or false.

  • mode: The type of certificate registration for this course (honor or certified).

  • url: URL to the downloadable version of the certificate, if exists.

  • course_progress: Contains information about how many assignments are in the course and how many assignments the student has completed.

  • total_assignments_count: Total course’s assignments count.

  • assignments_completed: Assignments witch the student has completed.

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'>)#
get_primary_enrollment_by_latest_enrollment_or_progress() CourseEnrollment | None#

Gets primary enrollment obj by latest enrollment or latest progress on the course.

get_queryset()#

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

get_same_org_mobile_available_enrollments() list[CourseEnrollment]#

Gets list with CourseEnrollment for mobile available courses.

get_serializer_class()#

Return the class to use for the serializer. Defaults to using self.serializer_class.

You may want to override this if you need to provide different serializations depending on the incoming request.

(Eg. admins get full serialization, others get basic serialization)

get_serializer_context()#

Extra context provided to the serializer class.

get_user() User#

Get user object by username.

is_org(check_org, course_org)#

Check course org matches request org param or no param provided

list(request, *args, **kwargs)#
lookup_field = 'username'#
pagination_class = None#
property paginator#

Override API View paginator property to dynamically determine pagination class

Implements solutions from the discussion at https://www.github.com/encode/django-rest-framework/issues/6397.

permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>, <class 'edx_rest_framework_extensions.permissions.IsUserInUrl'>)#
property queryset_for_user#

Find and return the list of course enrollments for the user.

In v4 added filtering by statuses.

property user_timezone#

Get the user’s timezone.

class lms.djangoapps.mobile_api.users.views.UserCourseEnrollmentsV4Pagination#

Bases: DefaultPagination

Pagination for UserCourseEnrollments API v4.

max_page_size = 50#
page_size = 5#
class lms.djangoapps.mobile_api.users.views.UserCourseStatus(**kwargs)#

Bases: APIView

Use Cases

Get or update the ID of the module that the specified user last visited in the specified course.

Get ID of the last completed block in case of version v1

Example Requests

GET /api/mobile/{version}/users/{username}/course_status_info/{course_id}

PATCH /api/mobile/{version}/users/{username}/course_status_info/{course_id}

PATCH Parameters

The body of the PATCH request can include the following parameters.

  • last_visited_module_id={module_id}

  • modification_date={date}

    The modification_date parameter is optional. If it is present, the update will only take effect if the modification_date in the request is later than the modification_date saved on the server.

Response Values

If the request is successful, the request returns an HTTP 200 “OK” response.

The HTTP 200 response has the following values.

  • last_visited_module_id: The ID of the last module that the user visited in the course.

  • last_visited_module_path: The ID of the modules in the path from the last visited module to the course block.

For version v1 GET request response includes the following values.

  • last_visited_block_id: ID of the last completed block.

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'>)#
dispatch(request, *args, **kwargs)#

.dispatch() is pretty much the same as Django’s regular dispatch, but with extra hooks for startup, finalize, and exception handling.

get(request, course, *args, **kwargs)#

Get the ID of the module that the specified user last visited in the specified course.

http_method_names = ['get', 'patch']#
patch(request, course, *args, **kwargs)#

Update the ID of the module that the specified user last visited in the specified course.

permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>, <class 'edx_rest_framework_extensions.permissions.IsUserInUrl'>)#
class lms.djangoapps.mobile_api.users.views.UserDetail(**kwargs)#

Bases: RetrieveAPIView

Use Case

Get information about the specified user and access other resources the user has permissions for.

Users are redirected to this endpoint after they sign in.

You can use the course_enrollments value in the response to get a list of courses the user is enrolled in.

Example Request

GET /api/mobile/{version}/users/{username}

Response Values

If the request is successful, the request returns an HTTP 200 “OK” response.

The HTTP 200 response has the following values.

  • course_enrollments: The URI to list the courses the currently signed in user is enrolled in.

  • email: The email address of the currently signed in user.

  • id: The ID of the user.

  • name: The full name of the currently signed in user.

  • username: The username of the currently signed in 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'>)#
get_serializer_context()#

Extra context provided to the serializer class.

lookup_field = 'username'#
permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>, <class 'edx_rest_framework_extensions.permissions.IsUserInUrl'>)#
serializer_class#

alias of UserSerializer

class lms.djangoapps.mobile_api.users.views.UserEnrollmentsStatus(**kwargs)#

Bases: APIView

Use Case

Get information about user’s enrolments status.

Returns active enrolment status if user was enrolled for the course less than 30 days ago or has progressed in the course in the last 30 days. Otherwise, the registration is considered inactive.

USER_ENROLLMENTS_LIMIT - adds users enrollments query limit to safe API from possible DDOS attacks.

Example Request

GET /api/mobile/{api_version}/users/<user_name>/enrollments_status/

Response Values

If the request for information about the user’s enrolments is successful, the request returns an HTTP 200 “OK” response.

The HTTP 200 response has the following values.

  • course_id (str): The course id associated with the user’s enrollment.

  • course_name (str): The course name associated with the user’s enrollment.

  • recently_active (bool): User’s course enrolment status.

The HTTP 200 response contains a list of dictionaries that contain info about each user’s enrolment status.

Example Response

```json [

{

“course_id”: “course-v1:a+a+a”, “course_name”: “a”, “recently_active”: true

}, {

“course_id”: “course-v1:b+b+b”, “course_name”: “b”, “recently_active”: true

}, {

“course_id”: “course-v1:c+c+c”, “course_name”: “c”, “recently_active”: false

USER_ENROLLMENTS_LIMIT = 500#
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'>)#
get(request, *args, **kwargs) Response#

Gets user’s enrollments status.

permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>, <class 'edx_rest_framework_extensions.permissions.IsUserInUrl'>)#
lms.djangoapps.mobile_api.users.views.my_user_info(request, *args, **kwargs)#

Redirect to the currently-logged-in user’s info page

Module contents#

User API