openedx.core.djangoapps.programs package#

Subpackages#

Submodules#

openedx.core.djangoapps.programs.api module#

Python APIs exposed by the Programs app to other in-process apps.

openedx.core.djangoapps.programs.api.is_user_enrolled_in_program_type(user, program_type_slug, paid_modes_only=False, enrollments=None, entitlements=None)#

This method will look at the learners Enrollments and Entitlements to determine if a learner is enrolled in a Program of the given type.

NOTE: This method relies on the Program Cache right now. The goal is to move away from this in the future.

Parameters:
  • user (User) – The user we are looking for.

  • program_type_slug (str) – The slug of the Program type we are looking for.

  • paid_modes_only (bool) – Request if the user is enrolled in a Program in a paid mode, False by default.

  • enrollments (List[Dict]) – Takes a serialized list of CourseEnrollments linked to the user

  • entitlements (List[CourseEntitlement]) – Take a list of CourseEntitlement objects linked to the user

  • NOTE – Both enrollments and entitlements will be collected if they are not passed in. They are available

  • collected (as parameters in case they were already) –

  • areas. (to save duplicate queries in high traffic) –

Returns:

True is the user is enrolled in programs of the requested type

Return type:

bool

openedx.core.djangoapps.programs.apps module#

Programs Configuration

class openedx.core.djangoapps.programs.apps.ProgramsConfig(app_name, app_module)#

Bases: AppConfig

Default configuration for the “openedx.core.djangoapps.programs” Django application.

name = 'openedx.core.djangoapps.programs'#
ready()#

Override this method in subclasses to run code when Django starts.

openedx.core.djangoapps.programs.forms module#

Forms for discussions.

class openedx.core.djangoapps.programs.forms.ProgramDiscussionsConfigurationForm(*args, **kwargs)#

Bases: ModelForm

Custom ProgramDiscussionsConfiguration form for admin page

class Meta#

Bases: object

fields = '__all__'#
model#

alias of ProgramDiscussionsConfiguration

base_fields = {'enabled': <django.forms.fields.BooleanField object>, 'lti_configuration': <django.forms.models.ModelChoiceField object>, 'pii_share_email': <django.forms.fields.BooleanField object>, 'pii_share_username': <django.forms.fields.BooleanField object>, 'program_uuid': <django.forms.fields.CharField object>, 'provider_type': <django.forms.fields.CharField object>}#
declared_fields = {'pii_share_email': <django.forms.fields.BooleanField object>, 'pii_share_username': <django.forms.fields.BooleanField object>}#
property media#

Return all media required to render the widgets on this form.

save(commit=True)#

Save this form’s self.instance object if commit=True. Otherwise, add a save_m2m() method to the form which can be called after the instance is saved manually at a later time. Return the model instance.

class openedx.core.djangoapps.programs.forms.ProgramLiveConfigurationForm(*args, **kwargs)#

Bases: ModelForm

Custom ProgramLiveConfigurationForm form for admin page

class Meta#

Bases: object

fields = '__all__'#
model#

alias of ProgramLiveConfiguration

base_fields = {'enabled': <django.forms.fields.BooleanField object>, 'lti_configuration': <django.forms.models.ModelChoiceField object>, 'pii_share_email': <django.forms.fields.BooleanField object>, 'pii_share_username': <django.forms.fields.BooleanField object>, 'program_uuid': <django.forms.fields.CharField object>, 'provider_type': <django.forms.fields.CharField object>}#
declared_fields = {'pii_share_email': <django.forms.fields.BooleanField object>, 'pii_share_username': <django.forms.fields.BooleanField object>}#
property media#

Return all media required to render the widgets on this form.

save(commit=True)#

Save this form’s self.instance object if commit=True. Otherwise, add a save_m2m() method to the form which can be called after the instance is saved manually at a later time. Return the model instance.

openedx.core.djangoapps.programs.models module#

Models providing Programs support for the LMS and Studio.

class openedx.core.djangoapps.programs.models.AbstractProgramLTIConfiguration(*args, **kwargs)#

Bases: TimeStampedModel

Associates a program with a LTI provider and configuration

class Meta#

Bases: object

abstract = False#
created#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

enabled#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod get(program_uuid)#

Lookup a program discussion configuration by program uuid.

get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
lti_configuration#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

lti_configuration_id#
modified#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

program_uuid#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

provider_type#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class openedx.core.djangoapps.programs.models.ProgramDiscussionsConfiguration(created, modified, program_uuid, enabled, lti_configuration, provider_type)#

Bases: AbstractProgramLTIConfiguration

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

created#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

enabled#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
history = <django.db.models.manager.HistoryManagerFromHistoricalQuerySet object>#
lti_configuration#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

lti_configuration_id#
modified#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
program_uuid#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

provider_type#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

save_without_historical_record(*args, **kwargs)#

Save model without saving a historical record

Make sure you know what you’re doing before you use this method.

class openedx.core.djangoapps.programs.models.ProgramLiveConfiguration(created, modified, program_uuid, enabled, lti_configuration, provider_type)#

Bases: AbstractProgramLTIConfiguration

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

created#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

enabled#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
history = <django.db.models.manager.HistoryManagerFromHistoricalQuerySet object>#
lti_configuration#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

lti_configuration_id#
modified#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
program_uuid#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

provider_type#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

save_without_historical_record(*args, **kwargs)#

Save model without saving a historical record

Make sure you know what you’re doing before you use this method.

class openedx.core.djangoapps.programs.models.ProgramsApiConfig(*args, **kwargs)#

Bases: ConfigurationModel

This model no longer fronts an API, but now sets a few config-related values for the idea of programs in general.

A rename to ProgramsConfig would be more accurate, but costly in terms of developer time.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

change_date#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

changed_by#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

changed_by_id#
enabled#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=True, **kwargs)#
get_previous_by_change_date(*, field=<django.db.models.fields.DateTimeField: change_date>, is_next=False, **kwargs)#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

marketing_path#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

openedx.core.djangoapps.programs.signals module#

This module contains signals / handlers related to programs.

openedx.core.djangoapps.programs.signals.handle_course_cert_awarded(sender, user, course_key, mode, status, **kwargs)#

If programs is enabled and a learner is awarded a course certificate, schedule a celery task to process any programs certificates for which the learner may now be eligible.

Parameters:
  • sender – class of the object instance that sent this signal

  • user – django.contrib.auth.User - the user to whom a cert was awarded

  • course_key – refers to the course run for which the cert was awarded

  • mode – mode / certificate type, e.g. “verified”

  • status – either “downloadable” or “generating”

Returns:

None

openedx.core.djangoapps.programs.signals.handle_course_cert_changed(sender, user, course_key, mode, status, **kwargs)#

If a learner is awarded a course certificate, schedule a celery task to process that course certificate

Parameters:
  • sender – class of the object instance that sent this signal

  • user – django.contrib.auth.User - the user to whom a cert was awarded

  • course_key – refers to the course run for which the cert was awarded

  • mode – mode / certificate type, e.g. “verified”

  • status – “downloadable”

Returns:

None

openedx.core.djangoapps.programs.signals.handle_course_cert_date_change(sender, course_key, **kwargs)#

If a course-run’s certificate_available_date is updated, schedule a celery task to update the visible_date attribute of all (course) credentials awarded in the Credentials service.

Parameters:

course_key (CourseLocator) – refers to the course whose certificate_available_date was updated.

openedx.core.djangoapps.programs.signals.handle_course_cert_revoked(sender, user, course_key, mode, status, **kwargs)#

If programs is enabled and a learner’s course certificate is revoked, schedule a celery task to revoke any related program certificates.

Parameters:
  • sender – class of the object instance that sent this signal

  • user – django.contrib.auth.User - the user for which a cert was revoked

  • course_key – refers to the course run for which the cert was revoked

  • mode – mode / certificate type, e.g. “verified”

  • status – revoked

Returns:

None

openedx.core.djangoapps.programs.tasks module#

This file contains celery tasks for programs-related functionality.

openedx.core.djangoapps.programs.tasks.award_program_certificate(client, user, program_uuid, visible_date)#

Issue a new certificate of completion to the given student for the given program.

Parameters:
  • client – credentials API client (requests.Session)

  • user – The student’s user data

  • program_uuid – uuid of the completed program

  • visible_date – when the program credential should be visible to user

Returns:

None

openedx.core.djangoapps.programs.tasks.get_certified_programs(student)#

Find the UUIDs of all the programs for which the student has already been awarded a certificate.

Parameters:

student – User object representing the student

Returns:

UUIDs of the programs for which the student has been awarded a certificate

Return type:

str[]

openedx.core.djangoapps.programs.tasks.get_completed_programs(site, student)#

Given a set of completed courses, determine which programs are completed.

Parameters:
  • site (Site) – Site for which data should be retrieved.

  • student (User) – Representing the student whose completed programs to check for.

Returns:

visible_dates}

Return type:

dict of {program_UUIDs

openedx.core.djangoapps.programs.tasks.get_inverted_programs(student)#

Get programs keyed by course run ID.

Parameters:

student (User) – Representing the student whose programs to check for.

Returns:

dict, programs keyed by course run ID

openedx.core.djangoapps.programs.tasks.get_revokable_program_uuids(course_specific_programs, student)#

Get program uuids for which certificate to be revoked.

Checks for existing learner certificates and filter out the program UUIDS for which a certificate needs to be revoked.

Parameters:
  • course_specific_programs (dict[]) – list of programs specific to a course

  • student (User) – Representing the student whose programs to check for.

Returns:

list if program UUIDs for which certificates to be revoked

openedx.core.djangoapps.programs.tasks.post_course_certificate(client, username, certificate, visible_date, date_override=None, org=None)#

POST a certificate that has been updated to Credentials

openedx.core.djangoapps.programs.tasks.post_course_certificate_configuration(client, cert_config, certificate_available_date=None)#

Make a POST request to the Credentials IDA’s course_certificates endpoint (/api/v2/course_certificates/). This endpoint manages the course certificate configurations within the Credentials IDA.

Parameters:
  • client (Session) – An authenticated Credentials API Client

  • cert_config (Dict) – A dictionary containing course metadata (course-run key and mode as Strings) important to the Course Certificate Configuration.

  • certificate_available_date (Str) – The desired Certificate Available Date for the Course Certificate Configuration in the form of an ISO 8601 DateTime String.

openedx.core.djangoapps.programs.tasks.revoke_program_certificate(client, username, program_uuid)#

Revoke a certificate of the given student for the given program.

Parameters:
  • client – credentials API client (requests.Session)

  • username – The username of the student

  • program_uuid – uuid of the program

Returns:

None

openedx.core.djangoapps.programs.utils module#

Helper functions for working with Programs.

class openedx.core.djangoapps.programs.utils.ProgramDataExtender(program_data, user, mobile_only=False)#

Bases: object

Utility for extending program data meant for the program detail page with user-specific (e.g., CourseEnrollment) data.

Parameters:
  • program_data (dict) – Representation of a program.

  • user (User) – The user whose enrollments to inspect.

extend()#

Execute extension handlers, returning the extended data.

class openedx.core.djangoapps.programs.utils.ProgramMarketingDataExtender(program_data, user)#

Bases: ProgramDataExtender

Utility for extending program data meant for the program marketing page which lives in the edx-platform git repository with user-specific (e.g., CourseEnrollment) data, pricing data, and program instructor data.

Parameters:
  • program_data (dict) – Representation of a program.

  • user (User) – The user whose enrollments to inspect.

extend()#

Execute extension handlers, returning the extended data.

class openedx.core.djangoapps.programs.utils.ProgramProgressMeter(site, user, enrollments=None, uuid=None, mobile_only=False, include_course_entitlements=True)#

Bases: object

Utility for gauging a user’s progress towards program completion.

Parameters:

user (User) – The user for which to find programs.

Keyword Arguments:
  • enrollments (list) – List of the user’s enrollments.

  • uuid (str) – UUID identifying a specific program. If provided, the meter will only inspect this one program, not all programs the user may be engaged with.

completed_course_runs#

Determine which course runs have been completed by the user.

Returns:

list of dicts, each representing a course run certificate

property completed_programs_with_available_dates#

Calculate the available date for completed programs based on course runs.

Returns a dict of {uuid_string: available_datetime}

course_runs_with_state#

Determine which course runs have been completed and failed by the user.

A course run is considered completed for a user if they have a certificate in the correct state and the certificate is available.

Returns:

dict with a list of completed and failed runs

engaged_programs#

Derive a list of programs in which the given user is engaged.

Returns:

list of program dicts, ordered by most recent enrollment

failed_course_runs#

Determine which course runs have been failed by the user.

Returns:

list of strings, each a course run ID

invert_programs()#

Intersect programs and enrollments.

Builds a dictionary of program dict lists keyed by course run ID and by course UUID. The resulting dictionary is suitable in applications where programs must be filtered by the course runs or courses they contain (e.g., the student dashboard).

Returns:

defaultdict, programs keyed by course run ID

progress(programs=None, count_only=True)#

Gauge a user’s progress towards program completion.

Keyword Arguments:
  • programs (list) – Specific list of programs to check the user’s progress against. If left unspecified, self.engaged_programs will be used.

  • count_only (bool) – Whether or not to return counts of completed, in progress, and unstarted courses instead of serialized representations of the courses.

Returns:

list of dict, each containing information about a user’s progress

towards completing a program.

openedx.core.djangoapps.programs.utils.attach_program_detail_url(programs, mobile_only=False)#

Extend program representations by attaching a URL to be used when linking to program details.

Facilitates the building of context to be passed to templates containing program data.

Parameters:

programs (list) – Containing dicts representing programs.

Returns:

list, containing extended program dicts

openedx.core.djangoapps.programs.utils.get_buy_subscription_url(program_uuid, skus)#

Returns the URL to the Subscription Purchase page for the given program UUID and course Skus.

openedx.core.djangoapps.programs.utils.get_certificates(user, extended_program)#

Find certificates a user has earned related to a given program.

Parameters:
  • user (User) – The user whose enrollments to inspect.

  • extended_program (dict) – The program for which to locate certificates. This is expected to be an “extended” program whose course runs already have certificate URLs attached.

Returns:

Contains dicts representing course run and program certificates the

given user has earned which are associated with the given program.

Return type:

list

openedx.core.djangoapps.programs.utils.get_industry_and_credit_pathways(program_data, site)#

Returns pathways of a program.

openedx.core.djangoapps.programs.utils.get_logged_in_program_certificate_url(certificate_url)#
openedx.core.djangoapps.programs.utils.get_program_and_course_data(site, user, program_uuid, mobile_only=False)#

Returns program and course data associated with the given user.

openedx.core.djangoapps.programs.utils.get_program_marketing_url(programs_config, mobile_only=False)#

Build a URL used to link to programs on the marketing site.

openedx.core.djangoapps.programs.utils.get_program_subscriptions_marketing_url()#

Build a URL used to link to subscription eligible programs on the marketing site.

openedx.core.djangoapps.programs.utils.get_program_urls(program_data)#

Returns important urls of program.

openedx.core.djangoapps.programs.utils.get_programs_subscription_data(user, program_uuid=None)#

Returns the subscription data for a user’s program if uuid is specified else return data for user’s all subscriptions.

openedx.core.djangoapps.programs.utils.get_subscription_api_client(user)#

Returns an API client which can be used to make Subscriptions API requests.

openedx.core.djangoapps.programs.utils.is_user_enrolled_in_program_type(user, program_type_slug, paid_modes_only=False, enrollments=None, entitlements=None)#

This method will look at the learners Enrollments and Entitlements to determine if a learner is enrolled in a Program of the given type.

NOTE: This method relies on the Program Cache right now. The goal is to move away from this in the future.

Parameters:
  • user (User) – The user we are looking for.

  • program_type_slug (str) – The slug of the Program type we are looking for.

  • paid_modes_only (bool) – Request if the user is enrolled in a Program in a paid mode, False by default.

  • enrollments (List[Dict]) – Takes a serialized list of CourseEnrollments linked to the user

  • entitlements (List[CourseEntitlement]) – Take a list of CourseEntitlement objects linked to the user

  • NOTE – Both enrollments and entitlements will be collected if they are not passed in. They are available

  • collected (as parameters in case they were already) –

  • areas. (to save duplicate queries in high traffic) –

Returns:

True is the user is enrolled in programs of the requested type

Return type:

bool

Module contents#

Platform support for Programs.

This package is a thin wrapper around interactions with the Programs service, supporting learner- and author-facing features involving that service if and only if the service is deployed in the Open edX installation.

To ensure maximum separation of concerns, and a minimum of interdependencies, this package should be kept small, thin, and stateless.