openedx.core.djangoapps.catalog package

Contents

openedx.core.djangoapps.catalog package#

Subpackages#

Submodules#

openedx.core.djangoapps.catalog.api module#

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

openedx.core.djangoapps.catalog.api.get_course_run_details(course_key, fields_list)#

Retrieves course run details for a given course run key.

Params:

course_key (CourseKey): The identifier for the course. fields_list (List, string): A list of fields (as strings) of values we want returned.

Returns:

dict containing response from the Discovery API that includes the fields specified in fields_list

openedx.core.djangoapps.catalog.api.get_course_run_key_for_program_from_cache(program)#

Retrieves a list of Course Run Keys from the Program.

Params:

program (dict): A dictionary from the program cache containing the data for a program.

Returns:

A set of Course Run Keys.

Return type:

(set)

openedx.core.djangoapps.catalog.api.get_programs_by_type(site, program_type_slug)#

Retrieves a list of programs for the site whose type’s slug matches the parameter. Slug is used is used as a consistent value to check since ProgramType.name is a field that gets translated.

Params:

site (Site): The corresponding Site object to fetch programs for. program_type_slug (string): The type slug that matching programs must have.

Returns:

A list of programs (dicts) for the given site with the given type slug

openedx.core.djangoapps.catalog.api.get_programs_from_cache_by_uuid(uuids)#

Retrieves the programs for the provided UUIDS. Relies on the Program cache, if it is not updated or data is missing the result will be missing data or empty.

Params:

uuids (list): A list of Program UUIDs to get Program data for from the cache.

Returns:

list of dictionaries representing programs.

Return type:

(list)

openedx.core.djangoapps.catalog.apps module#

Configuration for Catalog

class openedx.core.djangoapps.catalog.apps.CatalogConfig(app_name, app_module)#

Bases: AppConfig

name = 'openedx.core.djangoapps.catalog'#
verbose_name = 'Catalog'#

openedx.core.djangoapps.catalog.cache module#

openedx.core.djangoapps.catalog.constants module#

Constants associated with catalog

class openedx.core.djangoapps.catalog.constants.PathwayType(*values)#

Bases: Enum

Allowed values for pathway_type.

CREDIT = 'credit'#
INDUSTRY = 'industry'#

openedx.core.djangoapps.catalog.models module#

Models governing integration with the catalog service.

class openedx.core.djangoapps.catalog.models.CatalogIntegration(*args, **kwargs)#

Bases: ConfigurationModel

Manages configuration for connecting to the catalog service and using its API.

API_NAME = 'catalog'#
CACHE_KEY = 'catalog.api.data'#
exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

cache_ttl#

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

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_internal_api_url()#

Returns the internal Catalog API URL associated with the request’s site.

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)#
get_service_user()#
id#

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

internal_api_url#

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

property is_cache_enabled#

Whether responses from the catalog API will be cached.

long_term_cache_ttl#

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

page_size#

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

service_username#

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.catalog.urls module#

Defines the URL routes for this app.

openedx.core.djangoapps.catalog.utils module#

Helper functions for working with the catalog service.

openedx.core.djangoapps.catalog.utils.check_catalog_integration_and_get_user(error_message_field)#

Checks that catalog integration is enabled, and if so, attempts to get and return the service user.

Parameters:

error_message_field (str) – The field that will be attempted to be retrieved when calling the api client. Used for the error message.

Returns:

The catalog integration service user if it exists, else None The catalog integration Object

Note: (This is necessary for future calls of functions using this method)

Return type:

Tuple of

openedx.core.djangoapps.catalog.utils.child_programs(program)#

Given a program, recursively find all child programs related to this program through its curricula.

openedx.core.djangoapps.catalog.utils.course_run_keys_for_program(parent_program)#

All of the course run keys associated with this parent_program, either via its curriculum field (looking at both the curriculum’s courses and child programs), or through the many-to-many courses field on the program.

openedx.core.djangoapps.catalog.utils.course_uuids_for_program(parent_program)#

All of the course uuids associated with this parent_program, either via its curriculum field (looking at both the curriculum’s courses and child programs), or through the many-to-many courses field on the program.

openedx.core.djangoapps.catalog.utils.format_price(price, symbol='$', code='USD')#

Format the price to have the appropriate currency and digits..

Parameters:
  • price – The price amount.

  • symbol – The symbol for the price (default: $)

  • code – The currency code to be appended to the price (default: USD)

Returns:

A formatted price string, i.e. ‘$10 USD’, ‘$10.52 USD’.

openedx.core.djangoapps.catalog.utils.get_catalog_api_base_url(site=None)#

Returns a base API url used to make Catalog API requests.

openedx.core.djangoapps.catalog.utils.get_catalog_api_client(user)#

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

openedx.core.djangoapps.catalog.utils.get_course_data(course_key_str, fields, querystring=None)#

Retrieve information about the course with the given course key.

Parameters:
  • course_key_str – key for the course about which we are retrieving information.

  • fields (List, string) – The given fields that you want to retrieve from API response.

  • querystring (dict) – Optional query string parameters.

Returns:

dict with details about specified course.

openedx.core.djangoapps.catalog.utils.get_course_run_data(course_run_id, fields)#

Retrieve information about the course run with the given course run id.

Parameters:
  • course_run_id – key for the course run about which we are retrieving information.

  • fields (List, string) – The given fields that you want to retrieve from API response.

Returns:

dict with details about specified course run.

openedx.core.djangoapps.catalog.utils.get_course_run_details(course_run_key, fields)#

Retrieve information about the course run with the given id

Parameters:

course_run_key – key for the course_run about which we are retrieving information

Returns:

dict with language, start date, end date, and max_effort details about specified course run

openedx.core.djangoapps.catalog.utils.get_course_runs()#

Retrieve all the course runs from the catalog service.

Returns:

list of dict with each record representing a course run.

openedx.core.djangoapps.catalog.utils.get_course_runs_for_course(course_uuid)#
openedx.core.djangoapps.catalog.utils.get_course_uuid_for_course(course_run_key)#

Retrieve the Course UUID for a given course key

Parameters:
  • course_run_key (CourseKey) – A Key for a Course run that will be pulled apart to get just the information

  • Course (required for a)

Returns:

Course UUID and None if it was not retrieved.

Return type:

UUID

openedx.core.djangoapps.catalog.utils.get_currency_data()#

Retrieve currency data from the catalog service.

Returns:

list of dict, representing program types. dict, if a specific program type is requested.

openedx.core.djangoapps.catalog.utils.get_fulfillable_course_runs_for_entitlement(entitlement, course_runs)#

Looks through the list of course runs and returns the course runs that can be applied to the entitlement.

Parameters:
  • entitlement (CourseEntitlement) – The CourseEntitlement to which a

  • applied. (course run is to be)

  • course_runs (list) – List of course run that we would like to apply

  • entitlement. (to the)

Returns:

A list of sessions that a user can apply to the provided entitlement.

Return type:

list

openedx.core.djangoapps.catalog.utils.get_localized_price_text(price, request)#

Returns the localized converted price as string (ex. ‘$150 USD’)

If the users location has been added to the request, this will return the given price based on conversion rate from the Catalog service and return a localized string otherwise will return the default price in USD

openedx.core.djangoapps.catalog.utils.get_owners_for_course(course_uuid)#

Retrieves the course owner given a course uuid.

Arguments

course_uuid (string): Course UUID

openedx.core.djangoapps.catalog.utils.get_pathways(site, pathway_id=None)#

Read pathways from the cache. The cache is populated by a management command, cache_programs.

Parameters:

site (Site) – django.contrib.sites.models object

Keyword Arguments:

pathway_id (string) – id identifying a specific pathway to read from the cache.

Returns:

list of dict, representing pathways. dict, if a specific pathway is requested.

openedx.core.djangoapps.catalog.utils.get_program_types(name=None)#

Retrieve program types from the catalog service.

Keyword Arguments:

name (string) – Name identifying a specific program type.

Returns:

list of dict, representing program types. dict, if a specific program type is requested.

openedx.core.djangoapps.catalog.utils.get_programs(site: Site = None, uuid: str = None, uuids: List[str] = None, course: str = None, catalog_course_uuid: str = None, organization: str = None) str | List[str]#

Read programs from the cache.

The cache is populated by a management command, cache_programs.

Keyword Arguments:
  • site (Site) – django.contrib.sites.models object to fetch programs of.

  • uuid (string) – UUID identifying a specific program to read from the cache.

  • uuids (list of string) – UUIDs identifying a specific programs to read from the cache.

  • course (string) – course run id identifying a specific course run to read from the cache.

  • catalog_course_uuid (string) – Catalog Course UUID

  • organization (string) – short name for specific organization to read from the cache.

Returns:

list of str, representing programs. dict, if a specific program is requested.

openedx.core.djangoapps.catalog.utils.get_programs_by_type(site, program_type)#
Keyword Arguments:
  • site (Site) – The corresponding Site object to fetch programs for.

  • program_type (string) – The program_type that matching programs must have.

Returns:

A list of programs for the given site with the given program_type.

openedx.core.djangoapps.catalog.utils.get_programs_by_type_slug(site, program_type_slug)#
Keyword Arguments:
  • site (Site) – The corresponding Site object to fetch programs for.

  • program_type_slug (string) – The type slug that matching programs must have.

Returns:

A list of programs for the given site with the given type slug.

Slugs are a consistent identifier whereas type (used in get_programs_by_type) may be translated.

openedx.core.djangoapps.catalog.utils.get_programs_by_uuids(uuids: List[Any]) List[str]#

Gets a list of programs for the provided uuids

openedx.core.djangoapps.catalog.utils.get_programs_for_organization(organization)#

Retrieve list of program uuids authored by a given organization

openedx.core.djangoapps.catalog.utils.get_programs_with_type(site, include_hidden=True)#

Return the list of programs. You can filter the types of programs returned by using the optional include_hidden parameter. By default hidden programs will be included.

The program dict is updated with the fully serialized program type.

Parameters:

site (Site) – django.contrib.sites.models object

Keyword Arguments:

include_hidden (bool) – whether to include hidden programs

Returns:

list of dict, representing the active programs.

openedx.core.djangoapps.catalog.utils.get_pseudo_session_for_entitlement(entitlement)#

This function is used to pass pseudo-data to the front end, returning a single session, regardless of whether that session is currently available.

First tries to return the first available session. If there are no available sessions, will try to return the most recent session regardless of availability. Returns None if there are no sessions for that course.

openedx.core.djangoapps.catalog.utils.get_visible_sessions_for_entitlement(entitlement)#

Takes an entitlement object and returns the course runs that a user can currently enroll in.

openedx.core.djangoapps.catalog.utils.is_course_run_in_program(course_run_key, program)#

Check if a course run is part of a program.

Parameters:
  • program (dict) – program data, as returned by get_programs()

  • course_run_key (CourseKey|str)

Returns: bool

Whether the program exists AND the course run is part of it.

openedx.core.djangoapps.catalog.utils.normalize_program_type(program_type)#

Function that normalizes a program type string for use in a cache key.

openedx.core.djangoapps.catalog.views module#

openedx.core.djangoapps.catalog.views.cache_programs(request)#

Call the cache_programs management command.

This view is intended for use in testing contexts where the LMS can only be reached over HTTP (e.g., Selenium-based browser tests). The discovery service API the management command attempts to call should be stubbed out first.

Module contents#