Skip to content
Snippets Groups Projects
Commit e5b8f287 authored by Matt Tuchfarber's avatar Matt Tuchfarber
Browse files

Update with some preferences

parent 47255197
No related merge requests found
......@@ -79,7 +79,7 @@ class PluginSignals(object):
class PluginContextsViews(object):
STUDENT_DASHBOARD = u'student_dashboard'
COURSE_DASHBOARD = u'course_dashboard'
class PluginContexts(object):
......
from importlib import import_module
from logging import getLogger
from . import constants, registry
log = getLogger(__name__)
log = getLogger(__name__)
def get_plugins_view_context(project_type, view_name, existing_context={}):
"""
......@@ -18,11 +19,33 @@ def get_plugins_view_context(project_type, view_name, existing_context={}):
context_function_path = _get_context_function(app_config, project_type, view_name)
if context_function_path:
module_path, _, name = context_function_path.rpartition('.')
context_function = getattr(import_module(module_path), name)
plugin_context = context_function(existing_context)
try:
module = import_module(module_path)
except ImportError, ModuleNotFoundError:
log.exception("Failed to import %s plugin when creating %s context", module_path, view_name)
continue
context_function = getattr(module, name, None)
if context_function:
plugin_context = context_function(existing_context)
else:
log.exception(
"Failed to call %s function from %s plugin when creating %s context",
name,
module_path,
view_name
)
continue
# NOTE: If two plugins have try to set the same context keys, the last one
# called will overwrite the others.
for key in plugin_context:
if key in aggregate_context:
log.warning(
"Plugin %s is overwriting the value of %s for view %s",
app_config.__module__,
key,
view_name
)
aggregate_context.update(plugin_context)
return aggregate_context
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment