openedx.core.djangoapps.courseware_api package

Contents

openedx.core.djangoapps.courseware_api package#

Submodules#

openedx.core.djangoapps.courseware_api.apps module#

Courseware API Application Configuration

Signal handlers are connected here.

class openedx.core.djangoapps.courseware_api.apps.CoursewareAPIConfig(app_name, app_module)#

Bases: AppConfig

AppConfig for courseware API app

name = 'openedx.core.djangoapps.courseware_api'#
plugin_app = {'url_config': {'lms.djangoapp': {'app_name': 'openedx.core.djangoapps.courseware_api', 'namespace': 'courseware_api', 'regex': 'api/courseware/', 'relative_path': 'urls'}}}#

openedx.core.djangoapps.courseware_api.serializers module#

Course API Serializers. Representing course catalog data

class openedx.core.djangoapps.courseware_api.serializers.CourseInfoSerializer(*args, **kwargs)#

Bases: Serializer

Serializer for Course objects providing minimal data about the course.

For detailed information about what each field is for, see the docstring of the CoursewareInformation class.

class openedx.core.djangoapps.courseware_api.serializers.CourseProgramSerializer(*args, **kwargs)#

Bases: Serializer

get_progress(program)#
class openedx.core.djangoapps.courseware_api.serializers.ImageSerializer(*args, **kwargs)#

Bases: Serializer

Collection of URLs pointing to images of various sizes.

The URLs will be absolute URLs with the host set to the host of the current request. If the values to be serialized are already absolute URLs, they will be unchanged.

class Meta#

Bases: object

ref_name = 'courseware_api'#
class openedx.core.djangoapps.courseware_api.serializers.PrerequisiteCourseSerializer(*args, **kwargs)#

Bases: Serializer

Serializer for prerequisite course data with the serialized course key and display name.

openedx.core.djangoapps.courseware_api.urls module#

Contains all the URLs

openedx.core.djangoapps.courseware_api.utils module#

Courseware API Mixins.

openedx.core.djangoapps.courseware_api.utils.get_celebrations_dict(user, enrollment, course, browser_timezone)#

Returns a dict of celebrations that should be performed.

openedx.core.djangoapps.courseware_api.utils.serialize_upgrade_info(user, course_overview, enrollment)#

Return verified mode upgrade information, or None.

This is used in a few API views to provide consistent upgrade info to frontends.

openedx.core.djangoapps.courseware_api.views module#

Course API Views

class openedx.core.djangoapps.courseware_api.views.Celebration(**kwargs)#

Bases: DeveloperErrorViewMixin, APIView

Use Cases

Marks a particular celebration as complete

Example Requests

POST /api/courseware/celebration/{course_key}

Request Parameters

Body consists of the following fields:

  • first_section (bool): whether we should celebrate when a user finishes their first section of a course

  • weekly_goal (bool): whether we should celebrate when a user hits their weekly learning goal in a course

Returns

  • 200 or 201 or 202 on success with above fields.

  • 400 if an invalid parameter was sent.

  • 404 if the course is not available or cannot be seen.

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'>)#
http_method_names = ['post']#
permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
post(request, course_key_string, *args, **kwargs)#

Handle a POST request.

class openedx.core.djangoapps.courseware_api.views.CoursewareInformation(**kwargs)#

Bases: RetrieveAPIView

Use Cases

Request details for a course

Example Requests

GET /api/courseware/course/{course_key}

Response Values

Body consists of the following fields:

  • access_expiration: An object detailing when access to this course will expire
    • expiration_date: (str) When the access expires, in ISO 8601 notation

    • masquerading_expired_course: (bool) Whether this course is expired for the masqueraded user

    • upgrade_deadline: (str) Last chance to upgrade, in ISO 8601 notation (or None if can’t upgrade anymore)

    • upgrade_url: (str) Upgrade linke (or None if can’t upgrade anymore)

  • celebrations: An object detailing which celebrations to render
    • first_section: (bool) If the first section celebration should render

      Note: Also uses information from frontend so this value is not final

    • streak_length_to_celebrate: (int) The streak length to celebrate for the learner

    • streak_discount_enabled: (bool) If the frontend should render an upgrade discount for hitting the streak

    • weekly_goal: (bool) If the weekly goal celebration should render

  • course_goals:
    • selected_goal:
      • days_per_week: (int) The number of days the learner wants to learn per week

      • subscribed_to_reminders: (bool) Whether the learner wants email reminders about their goal

    • weekly_learning_goal_enabled: Flag indicating if this feature is enabled for this call

  • effort: A textual description of the weekly hours of effort expected

    in the course.

  • end: Date the course ends, in ISO 8601 notation

  • enrollment: Enrollment status of authenticated user
    • mode: audit, verified, etc

    • is_active: boolean

  • enrollment_end: Date enrollment ends, in ISO 8601 notation

  • enrollment_start: Date enrollment begins, in ISO 8601 notation

  • entrance_exam_data: An object containing information about the course’s entrance exam
    • entrance_exam_current_score: (float) The users current score on the entrance exam

    • entrance_exam_enabled: (bool) If the course has an entrance exam

    • entrance_exam_id: (str) The block id for the entrance exam if enabled. Will be a section (chapter)

    • entrance_exam_minimum_score_pct: (float) The minimum score a user must receive on the entrance exam

      to unlock the remainder of the course. Returned as a float (i.e. 0.7 for 70%)

    • entrance_exam_passed: (bool) Indicates if the entrance exam has been passed

  • id: A unique identifier of the course; a serialized representation

    of the opaque key identifying the course.

  • language: The language code for the course

  • media: An object that contains named media items. Included here:
    • course_image: An image to show for the course. Represented as an object with the following fields:

      • uri: The location of the image

  • name: Name of the course

  • offer: An object detailing upgrade discount information
    • code: (str) Checkout code

    • expiration_date: (str) Expiration of offer, in ISO 8601 notation

    • original_price: (str) Full upgrade price without checkout code; includes currency symbol

    • discounted_price: (str) Upgrade price with checkout code; includes currency symbol

    • percentage: (int) Amount of discount

    • upgrade_url: (str) Checkout URL

  • org: Name of the organization that owns the course

  • related_programs: A list of objects that contains program data related to the given course including:
    • progress: An object containing program progress:
      • complete: (int) Number of complete courses in the program (a course is completed if the user has

        earned a certificate for any of the nested course runs)

      • in_progress: (int) Number of courses in the program that are in progress (a course is in progress if

        the user has enrolled in any of the nested course runs)

      • not_started: (int) Number of courses in the program that have not been started

    • slug: (str) The program type

    • title: (str) The title of the program

    • url: (str) The link to the program’s landing page

    • uuid: (str) A unique identifier of the program

  • short_description: A textual description of the course

  • start: Date the course begins, in ISO 8601 notation

  • start_display: Readably formatted start of the course

  • start_type: Hint describing how start_display is set. One of:
    • “string”: manually set by the course author

    • “timestamp”: generated from the start timestamp

    • “empty”: no start date is specified

  • pacing: Course pacing. Possible values: instructor, self

  • user_timezone: User’s chosen timezone setting (or null for browser default)

  • user_has_passing_grade: Whether or not the effective user’s grade is equal to or above the courses minimum

    passing grade

  • course_exit_page_is_active: Flag for the learning mfe on whether or not the course exit page should display

  • certificate_data: data regarding the effective user’s certificate for the given course

  • verify_identity_url: URL for a learner to verify their identity. Only returned for learners enrolled in a

    verified mode. Will update to reverify URL if necessary.

  • verification_status: The verification status of the effective user in the course. Possible values:
    • ‘none’: No verification has been created for the user

    • ‘expired’: The verification has expired

    • ‘approved’: The verification has been approved

    • ‘pending’: The verification is pending

    • ‘must_reverify’: The user must reverify their identity

  • linkedin_add_to_profile_url: URL to add the effective user’s certificate to a LinkedIn Profile.

  • user_needs_integrity_signature: Whether the user needs to sign the integrity agreement for the course

  • learning_assistant_enabled: Whether the Xpert Learning Assistant is enabled for the requesting user

  • show_courseware_link: Whether the courseware link should be shown in the course details page

  • is_course_full: Whether the course is full

  • can_enroll: Whether the user can enroll in the course

  • invitation_only: Whether the course is invitation only

  • is_shib_course: Whether the course is a Shibboleth course

  • allow_anonymous: Whether the course allows anonymous access

  • ecommerce_checkout: Whether the course has an ecommerce checkout

  • single_paid_mode: An object representing the single paid mode for the course, if it exists
    • sku: (str) The SKU for the single paid mode

    • name: (str) The name of the single paid mode

    • min_price: (str) The minimum price for the single paid mode, formatted with the currency symbol

    • description: (str) The description of the single paid mode

  • ecommerce_checkout_link: The ecommerce checkout link for the course, if it exists

  • course_image_urls: A list of course image URLs

  • start_date_is_still_default: Whether the course start date is still the default value

  • advertised_start: The advertised start date of the course

  • course_price: The course price, formatted with the currency symbol

  • pre_requisite_courses: A list of pre-requisite courses for the course

  • about_sidebar_html: The HTML content for the course about section, if enabled

  • display_number_with_default: The course number with the org name, if set

  • display_org_with_default: The org name with the course number, if set

  • content_type_gating_enabled: Whether the content type gating is enabled for the course

  • show_calculator: Whether the calculator should be shown in the course details page

  • can_access_proctored_exams: Whether the user is eligible to access proctored exams

  • notes: An object containing note settings for the course
    • enabled: Boolean indicating whether edxnotes feature is enabled for the course

    • visible: Boolean indicating whether notes are visible in the course

  • marketing_url: The marketing URL for the course

  • overview: The overview HTML content for the course

  • license: The license for the course

Parameters:

requested_fields (optional) comma separated list:

If set, then only those fields will be returned.

username (optional) username to masquerade as (if requesting user is staff)

Returns

  • 200 on success with above fields.

  • 400 if an invalid parameter was sent or the username was not provided for an authenticated request.

  • 403 if a user who does not have permission to masquerade as another user specifies a username other than their own.

  • 404 if the course is not available or cannot be seen.

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.

finalize_response(request, response, *args, **kwargs)#

Return the final response, exposing the ‘Date’ header for computing relative time to the dates in the data.

Important dates such as ‘access_expiration’ are enforced server-side based on correct time; client-side clocks are frequently substantially far off which could lead to inaccurate messaging and incorrect expectations. Therefore, any messaging about those dates should be based on the server time and preferably in relative terms (time remaining); the ‘Date’ header is a straightforward and generalizable way for client-side code to get this reference.

get_object()#

Return the requested course object, if the user has appropriate permissions.

get_serializer_context()#

Return extra context to be used by the serializer class.

serializer_class#

alias of CourseInfoSerializer

set_last_seen_courseware_timezone(user)#

The timezone in the user’s account is frequently not set. This method sets a user’s recent timezone that can be used as a fallback

class openedx.core.djangoapps.courseware_api.views.CoursewareMeta(course_key, request, username='')#

Bases: object

Encapsulates courseware and enrollment metadata.

property about_sidebar_html#

Returns the HTML content for the course about section.

property access_expiration#
property advertised_start#

Returns the advertised start date of the course.

property allow_anonymous#

Returns a boolean representing whether the course allows anonymous access.

property can_access_proctored_exams#

Returns if the user is eligible to access proctored exams

property can_enroll#

Returns a boolean representing whether the user can enroll in the course.

property celebrations#

Returns a dict of celebrations that should be performed.

property certificate_data#

Returns certificate data if the effective_user is enrolled. Note: certificate data can be None depending on learner and/or course state.

property content_type_gating_enabled#
property course_exit_page_is_active#

Returns a boolean on if the course exit page is active

property course_goals#

Returns a dict of course goals

course_grade#

Returns the Course Grade for the effective user in the course

Cached property since we use this twice in the class and don’t want to recreate the entire grade.

property course_image_urls#

Returns a list of course image URLs.

property course_price#

Returns the course price, formatted with the currency symbol.

property ecommerce_checkout#

Returns a boolean representing whether the course has an ecommerce checkout.

Returns the ecommerce checkout link for the course.

property enrollment#

Return enrollment information.

property entrance_exam_data#

Returns Entrance Exam data for the course

Although some of the fields will have values (i.e. entrance_exam_minimum_score_pct and entrance_exam_passed), nothing will be used unless entrance_exam_enabled is True.

property invitation_only#

Returns a boolean representing whether the course is invitation only.

property is_course_full#

Returns a boolean representing whether the course is full.

property is_integrity_signature_enabled#

Django setting for the integrity signature feature.

property is_shib_course#

Returns a boolean representing whether the course is a Shibboleth course.

property language#
property learning_assistant_enabled#

Returns a boolean representing whether the requesting user should have access to the Xpert Learning Assistant.

property license#
property linkedin_add_to_profile_url#

Returns a URL to add a certificate to a LinkedIn profile (will autofill fields).

Requires LinkedIn sharing to be enabled, either via a site configuration or a LinkedInAddToProfileConfiguration object being enabled.

property notes#

Return whether edxnotes is enabled and visible.

property offer#
property overview#

Returns the overview HTML content for the course.

property pre_requisite_courses#

Returns a list of pre-requisite courses for the course.

property related_programs#

Returns related program data if the effective_user is enrolled. Note: related programs can be None depending on the course.

Returns a boolean representing whether the courseware link should be shown in the course details page.

property single_paid_mode#

Returns a dict representing the single paid mode for the course, if it exists.

property start_date_is_still_default#

Returns a boolean indicating whether the course start date is still the default value.

property user_has_passing_grade#

Returns a boolean on if the effective_user has a passing grade in the course

property user_needs_integrity_signature#

Boolean describing whether the user needs to sign the integrity agreement for a course.

property user_timezone#

Returns the user’s timezone setting (may be None)

property verification_status#

Returns a String of the verification status of learner.

property verify_identity_url#

Returns a String to the location to verify a learner’s identity Note: This might return an absolute URL (if the verification MFE is enabled) or a relative

URL. The serializer will make the relative URL absolute so any consumers can treat this as a full URL.

class openedx.core.djangoapps.courseware_api.views.Resume(**kwargs)#

Bases: DeveloperErrorViewMixin, APIView

Use Cases

Request the last completed block in a course

Example Requests

GET /api/courseware/resume/{course_key}

Response Values

Body consists of the following fields:

  • block: the last completed block key

  • section: the key to the section

  • unit: the key to the unit

If no completion data is available, the keys will be null

Returns

  • 200 on success with above fields.

  • 400 if an invalid parameter was sent.

  • 403 if a user who does not have permission to masquerade as another user specifies a username other than their own.

  • 404 if the course is not available or cannot be seen.

authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
get(request, course_key_string, *args, **kwargs)#

Return response to a GET request.

permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
class openedx.core.djangoapps.courseware_api.views.SequenceMetadata(**kwargs)#

Bases: DeveloperErrorViewMixin, APIView

Use Cases

Request details for a sequence/subsection

Example Requests

GET /api/courseware/sequence/{usage_key}

Response Values

Body consists of the following fields:

TODO

Returns

  • 200 on success with above fields.

  • 400 if an invalid parameter was sent.

  • 403 if a user who does not have permission to masquerade as another user specifies a username other than their own.

  • 404 if the course/usage_key is not available or cannot be seen.

  • 422 if the usage key is valid but does not have sequence metadata (like a unit or a problem)

authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
get(request, usage_key_string, *args, **kwargs)#

Return response to a GET request.

Module contents#