From 38de05c76cdd49c16af72cb7731a82e9c4ee639c Mon Sep 17 00:00:00 2001 From: Calen Pennington <cale@edx.org> Date: Fri, 6 Sep 2013 13:37:03 -0400 Subject: [PATCH] Include mixins in advanced component class loading and preview modules --- cms/djangoapps/contentstore/views/component.py | 14 ++++++++++++-- cms/djangoapps/contentstore/views/preview.py | 2 ++ lms/djangoapps/open_ended_grading/tests.py | 3 ++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/cms/djangoapps/contentstore/views/component.py b/cms/djangoapps/contentstore/views/component.py index b438676e239..724dc439d98 100644 --- a/cms/djangoapps/contentstore/views/component.py +++ b/cms/djangoapps/contentstore/views/component.py @@ -30,6 +30,7 @@ from .requests import _xmodule_recurse from .access import has_access from xmodule.x_module import XModuleDescriptor from xblock.plugin import PluginMissingError +from xblock.runtime import Mixologist __all__ = ['OPEN_ENDED_COMPONENT_TYPES', 'ADVANCED_COMPONENT_POLICY_KEY', @@ -137,6 +138,15 @@ def edit_subsection(request, location): ) +def load_mixed_class(category): + """ + Load an XBlock by category name, and apply all defined mixins + """ + component_class = XModuleDescriptor.load_class(category) + mixologist = Mixologist(settings.XBLOCK_MIXINS) + return mixologist.mix(component_class) + + @login_required def edit_unit(request, location): """ @@ -165,7 +175,7 @@ def edit_unit(request, location): component_templates = defaultdict(list) for category in COMPONENT_TYPES: - component_class = XModuleDescriptor.load_class(category) + component_class = load_mixed_class(category) # add the default template # TODO: Once mixins are defined per-application, rather than per-runtime, # this should use a cms mixed-in class. (cpennington) @@ -203,7 +213,7 @@ def edit_unit(request, location): # class? i.e., can an advanced have more than one entry in the # menu? one for default and others for prefilled boilerplates? try: - component_class = XModuleDescriptor.load_class(category) + component_class = load_mixed_class(category) component_templates['advanced'].append(( component_class.display_name.default or category, diff --git a/cms/djangoapps/contentstore/views/preview.py b/cms/djangoapps/contentstore/views/preview.py index 7fc669888e5..ccbb7fb5bb1 100644 --- a/cms/djangoapps/contentstore/views/preview.py +++ b/cms/djangoapps/contentstore/views/preview.py @@ -2,6 +2,7 @@ import logging import sys from functools import partial +from django.conf import settings from django.http import HttpResponse, Http404, HttpResponseBadRequest, HttpResponseForbidden from django.core.urlresolvers import reverse from django.contrib.auth.decorators import login_required @@ -116,6 +117,7 @@ def preview_module_system(request, preview_id, descriptor): user=request.user, xblock_field_data=preview_field_data, can_execute_unsafe_code=(lambda: can_execute_unsafe_code(course_id)), + mixins=settings.XBLOCK_MIXINS, ) diff --git a/lms/djangoapps/open_ended_grading/tests.py b/lms/djangoapps/open_ended_grading/tests.py index f3f0748c84a..27e6fd6059c 100644 --- a/lms/djangoapps/open_ended_grading/tests.py +++ b/lms/djangoapps/open_ended_grading/tests.py @@ -169,7 +169,8 @@ class TestPeerGradingService(ModuleStoreTestCase, LoginEnrollmentTestCase): replace_urls=None, xblock_field_data=lambda d: d._field_data, s3_interface=test_util_open_ended.S3_INTERFACE, - open_ended_grading_interface=test_util_open_ended.OPEN_ENDED_GRADING_INTERFACE + open_ended_grading_interface=test_util_open_ended.OPEN_ENDED_GRADING_INTERFACE, + mixins=settings.XBLOCK_MIXINS, ) self.descriptor = peer_grading_module.PeerGradingDescriptor(self.system, field_data, ScopeIds(None, None, None, None)) self.peer_module = self.descriptor.xmodule(self.system) -- GitLab