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:
AppConfigDefault 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:
ModelFormCustom 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:
ModelFormCustom 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:
TimeStampedModelAssociates a program with a LTI provider and configuration
- 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.parentis aForwardManyToOneDescriptorinstance.
- 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(*args, **kwargs)#
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.parentis aForwardManyToOneDescriptorinstance.
- 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 the model instance without creating a historical record.
Make sure you know what you’re doing before using this method.
- class openedx.core.djangoapps.programs.models.ProgramLiveConfiguration(*args, **kwargs)#
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.parentis aForwardManyToOneDescriptorinstance.
- 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 the model instance without creating a historical record.
Make sure you know what you’re doing before using this method.
- class openedx.core.djangoapps.programs.models.ProgramsApiConfig(*args, **kwargs)#
Bases:
ConfigurationModelThis 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.parentis aForwardManyToOneDescriptorinstance.
- 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 use of the Credentials IDA is enabled and a learner is awarded a course certificate, schedule a celery task to determine if the learner is also eligible to be awarded any program certificates.
- Parameters:
sender – class of the object instance that sent this signal
user (User) – The user to whom a course certificate was awarded
course_key (CourseLocator) – The course run key for which the course certificate was awarded
mode (str) – The “mode” of the course (e.g. Audit, Honor, Verified, etc.)
status (str) – The status of the course certificate that was awarded (e.g. “downloadable”)
- Returns:
None
- openedx.core.djangoapps.programs.signals.handle_course_cert_changed(sender, user, course_key, mode, status, **kwargs)#
When the system updates a course certificate, enqueue a celery task responsible for syncing this change in the Credentials IDA
* Important * While the current name of the enqueue’d task is award_course_certificate it is actually responsible for both awarding and revocation of course certificates in Credentials. *****************
- Parameters:
sender – class of the object instance that sent this signal
user (User) – The user to whom a course certificate was awarded
course_key (CourseLocator) – The course run key for which the course certificate was awarded
mode (str) – The “mode” of the course (e.g. Audit, Honor, Verified, etc.)
status (str) – The status of the course certificate that was awarded (e.g. “downloadable”)
- Returns:
None
- openedx.core.djangoapps.programs.signals.handle_course_cert_date_change(sender, course_key, **kwargs)#
When a course run’s configuration has been updated, and the system has detected an update related to the display behavior or availability date of the certificates issued in that course, we should enqueue celery tasks responsible for:
updating the certificate available date of the course run’s course certificate configuration in Credentials
- Parameters:
sender – class of the object instance that sent this signal
course_key (CourseLocator) – The course run key of the course run which was updated
- Returns:
None
- openedx.core.djangoapps.programs.signals.handle_course_cert_revoked(sender, user, course_key, mode, status, **kwargs)#
If use of the Credentials IDA is enabled and a learner has a course certificate revoked, schedule a celery task to determine if there are any program certificates that must be revoked too.
- Parameters:
sender – class of the object instance that sent this signal
user (User) – The user to whom a course certificate was revoked
course_key (CourseLocator) – The course run key for which the course certificate was revoked
mode (str) – The “mode” of the course (e.g. “audit”, “honor”, “verified”, etc.)
status (str) – The status of the course certificate that was revoked (e.g. “revoked”)
- Returns:
None
- openedx.core.djangoapps.programs.signals.handle_course_pacing_change(sender, updated_course_overview, **kwargs)#
If the pacing of a course run has been updated, we should enqueue the tasks responsible for updating the certificate available date (CAD) stored in the Credentials IDA’s internal records. This ensures that we are correctly managing the visibiltiy of certificates on learners’ program records.
- Parameters:
sender – class of the object instance that sent this signal
updated_course_overview (CourseOverview) – The course overview of the course run which was just updated
- Returns:
None
openedx.core.djangoapps.programs.tasks module#
This file contains celery tasks and utility functions responsible for syncing course and program certificate metadata between the monolith and the Credentials IDA.
- openedx.core.djangoapps.programs.tasks.award_program_certificate(client: Session, user: UserType, program_uuid: str) None#
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
- Returns:
None
- openedx.core.djangoapps.programs.tasks.get_certified_programs(student: UserType, raise_on_error: bool = False) List[str]#
Find the UUIDs of all the programs for which the student has already been awarded a certificate.
- Parameters:
student – User object representing the student
- Keyword Arguments:
raise_on_error (bool) – Reraise errors back to the caller, instead of returning empty results.
- 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: Site, student: UserType) Dict#
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:
availability dates
- Return type:
Dict of program_UUIDs
- openedx.core.djangoapps.programs.tasks.get_inverted_programs(student: UserType)#
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: List[Dict], student: UserType) List[str]#
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 of program UUIDs for which certificates to be revoked
- Raises:
HttpError, if the API call generated by get_certified_programs fails –
- openedx.core.djangoapps.programs.tasks.post_course_certificate(client: Session, username: str, certificate: GeneratedCertificateData, date_override: datetime | None = None, org: str | None = 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)#
Make a request to the Credentials IDA, requesting the system to revoke a program certificate from the given user in a 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:
objectUtility 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:
ProgramDataExtenderUtility 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:
objectUtility 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: list[dict | None] | None = None, count_only: bool = True) list[dict | None]#
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_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_urls(program_data)#
Returns important urls of program.
- 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.