enterprise package


enterprise.apps module

Enterprise Django application initialization.

class enterprise.apps.EnterpriseConfig(app_name, app_module)

Bases: django.apps.config.AppConfig

Configuration for the enterprise Django application.


Return User model for django.contrib.auth.

image_size = 4096
name = u'enterprise'

Perform other one-time initialization steps.

valid_extensions = [u'.png']

enterprise.constants module

Enterprise Django application constants.

enterprise.course_catalog_api module

Utilities to get details from the course catalog API.

class enterprise.course_catalog_api.CourseCatalogApiClient(user)

Bases: object

Object builds an API client to make calls to the Catalog API.


Return a list of all course catalogs, including name and ID.

Returns:List of catalogs available for the user.
Return type:list

Return specified course catalog.

Returns:catalog details if it is available for the user.
Return type:dict

Return the courses included in a single course catalog by ID.

Parameters:catalog_id (int) – The catalog ID we want to retrieve.
Returns:Courses of the catalog in question
Return type:list

Find common course modes for a set of course runs.

This function essentially returns an intersection of types of seats available for each course run.

Parameters:course_run_ids (Iterable[str]) – Target Course run IDs.
Returns:course modes found in all given course runs
Return type:set


# run1 has prof and audit, run 2 has the same get_common_course_modes([‘course-v1:run1’, ‘course-v1:run2’]) {‘prof’, ‘audit’}

# run1 has prof and audit, run 2 has only prof get_common_course_modes([‘course-v1:run1’, ‘course-v1:run2’]) {‘prof’}

# run1 has prof and audit, run 2 honor get_common_course_modes([‘course-v1:run1’, ‘course-v1:run2’]) {}

# run1 has nothing, run2 has prof get_common_course_modes([‘course-v1:run1’, ‘course-v1:run2’]) {}

# run1 has prof and audit, run 2 prof, run3 has audit get_common_course_modes([‘course-v1:run1’, ‘course-v1:run2’, ‘course-v1:run3’]) {}

# run1 has nothing, run 2 prof, run3 has prof get_common_course_modes([‘course-v1:run1’, ‘course-v1:run2’, ‘course-v1:run3’]) {}


Return the details of a single course by key - not a course run key.

Parameters:course_key (str) – The unique key for the course in question.
Returns:Details of the course in question.
Return type:dict

Return course_run data, including name, ID and seats.

Parameters:course_run_id (string) – Course run ID (aka Course Key) in string format.
Returns:Course run data provided by Course Catalog API.
Return type:dict
get_paginated_catalog_courses(catalog_id, page=1)

Return paginated resopnse for all catalog courses.

Returns:API response with links to next and previous pages.
Return type:dict

Return single program by name, or None if not found.

Parameters:program_title (string) – Program title as seen by students and in Course Catalog Admin
Returns:Program data provided by Course Catalog API
Return type:dict

Return single program by UUID, or None if not found.

Parameters:program_uuid (string) – Program UUID in string form
Returns:Program data provided by Course Catalog API
Return type:dict

enterprise.django_compatibility module

Abstracts incompatibilities between Django versions.

enterprise.lms_api module

enterprise.models module

enterprise.signals module

enterprise.tpa_pipeline module

enterprise.urls module

enterprise.utils module

Utility functions for enterprise app.

exception enterprise.utils.CourseCatalogApiError

Bases: exceptions.Exception

Exception to raise when we we received data from Course Catalog but it contained an error.

exception enterprise.utils.MultipleProgramMatchError(programs_matched, *args, **kwargs)

Bases: enterprise.utils.CourseCatalogApiError

Exception to raise when Course Catalog api returned multiple programs, while single program was expected.

exception enterprise.utils.NotConnectedToEdX(*args, **kwargs)

Bases: exceptions.Exception

Exception to raise when not connected to OpenEdX.

In general, this exception shouldn’t be raised, because this package is designed to be installed directly inside an existing OpenEdX platform.

exception enterprise.utils.NotConnectedToOpenEdX

Bases: exceptions.Exception

Exception to raise when we weren’t able to import needed resources.

This is raised when we try to use the resources, rather than on import, so that during testing we can load the module and mock out the resources we need.

enterprise.utils.build_notification_message(template_context, template_configuration=None)

Create HTML and plaintext message bodies for a notification.

We receive a context with data we can use to render, as well as an optional site template configration - if we don’t get a template configuration, we’ll use the standard, built-in template.

  • template_context (dict) – A set of data to render
  • template_configuration – A database-backed object with templates stored that can be used to render a notification.
enterprise.utils.consent_necessary_for_course(user, course_id)

Determine if consent is necessary before a user can access a course they’ve enrolled in.

  • user – The user attempting to access the course
  • course_id – The string ID of the course in question

Decorator that turns off signal handlers when loading fixture data.

Django docs instruct to avoid further changes to the DB if raw=True as it might not be in a consistent state. See https://docs.djangoproject.com/en/dev/ref/signals/#post-save


Return all fields’ names from a model.

According to Django documentation, get_all_field_names should become some monstrosity with chained iterable ternary nested in a list comprehension. For now, a simpler version of iterating over fields and getting their names work, but we might have to switch to full version in future.


Get url to catalog details admin page.

Parameters:catalog_id (int) – Catalog id for which to return catalog details url.
Returns:URL pointing to catalog details admin page for the give catalog id.


>>> get_catalog_admin_url_template(2)

Get template of catalog admin url.

URL template will contain a placeholder ‘{catalog_id}’ for catalog id.

Returns:A string containing template for catalog url.


>>> get_catalog_admin_url_template()
enterprise.utils.get_course_track_selection_url(course_run, query_parameters)

Return track selection url for the given course.

  • course_run (dict) – A dictionary containing course run metadata.
  • query_parameters (dict) – A dictionary containing query parameters to be added to course selection url.

(KeyError) – Raised when course run dict does not have ‘key’ key.


Course track selection url.

Return type:



Return the EnterpriseCustomer branding information based on enterprise customer uuid.

Parameters:ec_uuid (UUID) – a universally unique identifier for the enterprise customer.
Returns:EnterpriseCustomerBrandingConfiguration instance associated with the given enterprise customer uuid.

Return the EnterpriseCustomer branding information based on provider_id.

Parameters:identity_provider_id – There is 1:1 relation b/w EnterpriseCustomer and Identity provider.
Returns:EnterpriseCustomerBrandingConfiguration instance associated with the customer of given identity provider.

Return enterprise customer instance for given user.

Some users are associated with an enterprise customer via EnterpriseCustomerUser model,
  1. if given user is associated with any enterprise customer, return enterprise customer.
  2. otherwise return None.
Parameters:auth_user (contrib.auth.User) – Django User
Returns:enterprise customer associated with the current user.
Return type:(EnterpriseCustomer)

Get Identity Provider with given id.

Raises a ValueError if it third_party_auth app is not available.

Returns:Instance of ProviderConfig or None.

Get a list of identity providers choices for enterprise customer.

Returns:A list of choices of all identity providers, None if it can not get any available identity provider.
enterprise.utils.get_notification_subject_line(course_name, template_configuration=None)

Get a subject line for a notification email.

The method is designed to fail in a “smart” way; if we can’t render a database-backed subject line template, then we’ll fall back to a template saved in the Django settings; if we can’t render _that_ one, then we’ll fall through to a friendly string written into the code.

One example of a failure case in which we want to fall back to a stock template would be if a site admin entered a subject line string that contained a template tag that wasn’t available, causing a KeyError to be raised.

  • course_name (str) – Course name to be rendered into the string
  • template_configuration – A database-backed object with a stored subject line template
enterprise.utils.get_reversed_url_by_site(request, site, *args, **kwargs)

Get a function to do a standard Django reverse, and then apply that path to another site’s domain.

We use urlparse to split the url into its individual components, and then replace the netloc with the domain for the site in question. We then unparse the result into a URL string.

  • request – The Django request currently being processed
  • site (site) – The site we want to apply to the URL created
  • *args – Pass to the standard reverse function
  • **kwargs – Pass to the standard reverse function

Decorator that does nothing to the wrapped function.

If we’re unable to import social.pipeline.partial, which is the case in our CI platform, we need to be able to wrap the function with something.


Update the EdX Mako paths to point to our consent template.

Do nothing if we’re not connected to OpenEdX.

enterprise.utils.send_email_notification_message(user, enrolled_in, enterprise_customer, email_connection=None)

Send an email notifying a user about their enrollment in a course.

  • user – Either a User object or a PendingEnterpriseCustomerUser that we can use to get details for the email
  • enrolled_in (dict) –

    The dictionary contains details of the enrollable object (either course or program) that the user enrolled in. This MUST contain a name key, and MAY contain the other following keys:

    • url: A human-friendly link to the enrollable’s home page
    • type: Either course or program at present
    • branding: A special name for what the enrollable “is”; for example,
      “MicroMasters” would be the branding for a “MicroMasters Program”
    • start: A datetime object indicating when the enrollable will be available.
  • enterprise_customer – The EnterpriseCustomer that the enrollment was created using.
  • email_connection – An existing Django email connection that can be used without creating a new connection for each individual message
enterprise.utils.update_query_parameters(url, query_parameters)

Return url with updated query parameters.

  • url (str) – Original url whose query parameters need to be updated.
  • query_parameters (dict) – A dictionary containing query parameters to be added to course selection url.

slug identifier for the identity provider that can be used for identity verification of

users associated the enterprise customer of the given user.

Return type:


enterprise.validators module

Database models field validators.


:return Application configuration.


Validate that a particular image extension.


Validate that a particular image size.

enterprise.views module

Module contents

Your project description goes here.