edx_django_utils.plugins package#

Submodules#

edx_django_utils.plugins.constants module#

Constants/Enums used during interfacing with plugin system

class edx_django_utils.plugins.constants.PluginContexts#

Bases: object

The PluginContexts enum defines dictionary field names (and defaults) that can be specified by a Plugin App in order to configure the additional views it would like to add context into.

CONFIG = 'view_context_config'#
class edx_django_utils.plugins.constants.PluginSettings#

Bases: object

The PluginSettings enum defines dictionary field names (and defaults) that can be specified by a Plugin App in order to configure the settings that are injected into the project.

CONFIG = 'settings_config'#
DEFAULT_RELATIVE_PATH = 'settings'#
RELATIVE_PATH = 'relative_path'#
class edx_django_utils.plugins.constants.PluginSignals#

Bases: object

The PluginSignals enum defines dictionary field names (and defaults) that can be specified by a Plugin App in order to configure the signals that it receives.

CONFIG = 'signals_config'#
DEFAULT_RELATIVE_PATH = 'signals'#
DISPATCH_UID = 'dispatch_uid'#
RECEIVERS = 'receivers'#
RECEIVER_FUNC_NAME = 'receiver_func_name'#
RELATIVE_PATH = 'relative_path'#
SENDER_PATH = 'sender_path'#
SIGNAL_PATH = 'signal_path'#
class edx_django_utils.plugins.constants.PluginURLs#

Bases: object

The PluginURLs enum defines dictionary field names (and defaults) that can be specified by a Plugin App in order to configure the URLs that are injected into the project.

APP_NAME = 'app_name'#
CONFIG = 'url_config'#
DEFAULT_RELATIVE_PATH = 'urls'#
NAMESPACE = 'namespace'#
REGEX = 'regex'#
RELATIVE_PATH = 'relative_path'#

edx_django_utils.plugins.pluggable_override module#

Allows overriding existing functions and methods with alternative implementations.

edx_django_utils.plugins.pluggable_override.pluggable_override(override)#

This decorator allows overriding any function or method by pointing to an alternative implementation with override param. :param override: path to the alternative function

Example usage:

  1. Add this decorator to an existing function OVERRIDE_TRANSFORM is the variable name in settings that can be used for overriding this function. Remember to add the OVERRIDE_ prefix to the name to have the consistent namespace for the overrides.

    >>> @pluggable_override('OVERRIDE_TRANSFORM')
    ... def transform(value):
    ...     return value + 10
    
  2. Prepare an alternative implementation. It will have the same set of arguments as the original function, with the prev_fn added at the beginning.

    >>> def decrement(prev_fn, value):
    ...     if value >= 10:
    ...         return value - 1  # Return the decremented value.
    ...     else:
    ...         return prev_fn(value) - 1  # Call the original `transform` method before decrementing and returning.
    
  3. Specify the path in settings (e.g. in envs/private.py):
    >>> OVERRIDE_TRANSFORM = 'transform_plugin.decrement'
    

    You can also chain overrides: >>> OVERRIDE_TRANSFORM = [ … ‘transform_plugin.decrement’, … ‘transform_plugin.increment’, … ]

Another example:

  1. We want to limit access to a Django view (e.g. common.djangoapps.student.views.dashboard.student_dashboard) to allow only logged in users. To do this add OVERRIDE_DASHBOARD to the original function: >>> @pluggable_override(‘OVERRIDE_DASHBOARD’) … def student_dashboard(request): … … # The rest of the implementation is not relevant in this case.

  1. Prepare an alternative implementation (e.g. in envs/private.py to make this example simpler): >>> from django.contrib.auth.decorators import login_required … … def dashboard(prev_fn, request): … return login_required(prev_fn)(request) … … OVERRIDE_DASHBOARD = ‘lms.envs.private.dashboard’

edx_django_utils.plugins.plugin_apps module#

Methods to get plugin apps

Please remember to expose any new public methods in the __init__.py file.

edx_django_utils.plugins.plugin_apps.get_plugin_apps(project_type)#

Returns a list of all registered Plugin Apps, expected to be added to the INSTALLED_APPS list for the given project_type.

edx_django_utils.plugins.plugin_contexts module#

Various functions to get view contexts

Please remember to expose any new public methods in the __init__.py file.

edx_django_utils.plugins.plugin_contexts.get_plugins_view_context(project_type, view_name, existing_context=None)#

Returns a dict of additional view context. Will check if any plugin apps have that view in their view_context_config, and if so will call their selected function to get their context dicts.

Params:
project_type: a string that determines which project the view is being called in. See the

ProjectType enum in openedx/edx-platform djangoapps/plugins/constants.py#L14 for valid options for edx-platform.

view_name: a string that determines which view needs the additional context. These are globally unique and

noted in the api.py in the view’s app.

existing_context: a dictionary which includes all of the data that the page was going to render with prior

to the addition of each plugin’s context. This is what will be passed to plugins so they may choose what data to add to the view.

edx_django_utils.plugins.plugin_manager module#

Adds support for first class plugins that can be added to an IDA.

Please remember to expose any new public methods in the __init__.py file.

exception edx_django_utils.plugins.plugin_manager.PluginError#

Bases: Exception

Base Exception for when an error was found regarding plugins.

class edx_django_utils.plugins.plugin_manager.PluginManager#

Bases: object

Base class that manages plugins for an IDA.

classmethod get_available_plugins(namespace=None)#

Returns a dict of all the plugins that have been made available.

classmethod get_plugin(name, namespace=None)#

Returns the plugin with the given name.

edx_django_utils.plugins.plugin_settings module#

Functions that deal with settings related to plugins

Please remember to expose any new public methods in the __init__.py file.

edx_django_utils.plugins.plugin_settings.add_plugins(settings_path, project_type, settings_type)#

Updates the module at the given settings_path with all Plugin Settings appropriate for the given project_type and settings_type.

edx_django_utils.plugins.plugin_signals module#

Allows plugins to work with django signals

Please remember to expose any new public methods in the __init__.py file.

edx_django_utils.plugins.plugin_signals.connect_plugin_receivers(project_type)#

connects receivers to right signal

edx_django_utils.plugins.plugin_urls module#

Urls utility functions

Please remember to expose any new public methods in the __init__.py file.

edx_django_utils.plugins.plugin_urls.get_plugin_url_patterns(project_type)#

Returns a list of all registered Plugin URLs, expected to be added to the URL patterns for the given project_type.

edx_django_utils.plugins.registry module#

Code to create Registry of django app plugins

Please remember to expose any new public methods in the __init__.py file.

class edx_django_utils.plugins.registry.DjangoAppRegistry#

Bases: edx_django_utils.plugins.plugin_manager.PluginManager

DjangoAppRegistry is a registry of django app plugins.

edx_django_utils.plugins.registry.get_plugin_app_configs(project_type)#

edx_django_utils.plugins.utils module#

utils to help with imports

Please remember to expose any new public methods in the __init__.py file.

edx_django_utils.plugins.utils.get_module_path(app_config, plugin_config, plugin_cls)#
edx_django_utils.plugins.utils.import_attr(attr_path)#

Import and returns a module’s attribute at the specific path.

Parameters

form (attr_path should be of the) – {full_module_path}.attr_name

edx_django_utils.plugins.utils.import_attr_in_module(imported_module, attr_name)#

Import and returns the attribute with name attr_name in the given module.

edx_django_utils.plugins.utils.import_module(module_path)#

Import and returns the module at the specific path.

Parameters
  • module (module_path is the full path to the) –

  • name. (including the package) –

Module contents#

Plugins infrastructure

See README.rst for details.