Enterprise Django application initialization.
enterprise.apps.
EnterpriseConfig
(app_name, app_module)¶Bases: django.apps.config.AppConfig
Configuration for the enterprise Django application.
auth_user_model
¶Return User model for django.contrib.auth.
image_size
= 4096¶name
= u'enterprise'¶ready
()¶Perform other one-time initialization steps.
valid_extensions
= [u'.png']¶Enterprise Django application constants.
Utilities to get details from the course catalog API.
enterprise.course_catalog_api.
CourseCatalogApiClient
(user)¶Bases: object
Object builds an API client to make calls to the Catalog API.
DEFAULT_VALUE_SAFEGUARD
= <object object>¶get_all_catalogs
()¶Return a list of all course catalogs, including name and ID.
Returns: | List of catalogs available for the user. |
---|---|
Return type: | list |
get_catalog
(catalog_id)¶Return specified course catalog.
Returns: | catalog details if it is available for the user. |
---|---|
Return type: | dict |
get_catalog_courses
(catalog_id)¶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 |
get_common_course_modes
(course_run_ids)¶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 |
Examples
# 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’]) {}
get_course_details
(course_key)¶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 |
get_course_run
(course_run_id)¶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 |
Abstracts incompatibilities between Django versions.
Utility functions for enterprise app.
enterprise.utils.
CourseCatalogApiError
¶Bases: exceptions.Exception
Exception to raise when we we received data from Course Catalog but it contained an error.
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.
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.
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.
Parameters: |
|
---|
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.
Parameters: |
|
---|
enterprise.utils.
disable_for_loaddata
(signal_handler)¶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
enterprise.utils.
get_all_field_names
(model)¶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.
enterprise.utils.
get_catalog_admin_url
(catalog_id)¶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. |
Example
>>> get_catalog_admin_url_template(2)
"http://localhost:18381/admin/catalogs/catalog/2/change/"
enterprise.utils.
get_catalog_admin_url_template
()¶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. |
---|
Example
>>> get_catalog_admin_url_template()
"http://localhost:18381/admin/catalogs/catalog/{catalog_id}/change/"
enterprise.utils.
get_course_track_selection_url
(course_run, query_parameters)¶Return track selection url for the given course.
Parameters: | |
---|---|
Raises: |
|
Returns: | Course track selection url. |
Return type: | (str) |
enterprise.utils.
get_enterprise_branding_info_by_ec_uuid
(ec_uuid=None)¶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. |
enterprise.utils.
get_enterprise_branding_info_by_provider_id
(identity_provider_id=None)¶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. |
enterprise.utils.
get_enterprise_customer_for_user
(auth_user)¶Return enterprise customer instance for given user.
Parameters: | auth_user (contrib.auth.User) – Django User |
---|---|
Returns: | enterprise customer associated with the current user. |
Return type: | (EnterpriseCustomer) |
enterprise.utils.
get_identity_provider
(provider_id)¶Get Identity Provider with given id.
Raises a ValueError if it third_party_auth app is not available.
Returns: | Instance of ProviderConfig or None. |
---|
enterprise.utils.
get_idp_choices
()¶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.
Parameters: |
|
---|
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.
Parameters: |
|
---|
enterprise.utils.
null_decorator
(func)¶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.
enterprise.utils.
patch_mako_lookup
()¶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.
Parameters: |
|
---|
enterprise.utils.
update_query_parameters
(url, query_parameters)¶Return url with updated query parameters.
Parameters: | |
---|---|
Returns: |
|
Return type: | (slug) |
Database models field validators.
enterprise.validators.
get_app_config
()¶:return Application configuration.
enterprise.validators.
validate_image_extension
(value)¶Validate that a particular image extension.
enterprise.validators.
validate_image_size
(image)¶Validate that a particular image size.
Your project description goes here.