Commit 0cac1c3b by Calen Pennington

Merge pull request #881 from cpennington/dhm/editable_metadata

Include mixins in advanced component class loading and preview modules
parents 0099ee09 38de05c7
...@@ -30,6 +30,7 @@ from .requests import _xmodule_recurse ...@@ -30,6 +30,7 @@ from .requests import _xmodule_recurse
from .access import has_access from .access import has_access
from xmodule.x_module import XModuleDescriptor from xmodule.x_module import XModuleDescriptor
from xblock.plugin import PluginMissingError from xblock.plugin import PluginMissingError
from xblock.runtime import Mixologist
__all__ = ['OPEN_ENDED_COMPONENT_TYPES', __all__ = ['OPEN_ENDED_COMPONENT_TYPES',
'ADVANCED_COMPONENT_POLICY_KEY', 'ADVANCED_COMPONENT_POLICY_KEY',
...@@ -137,6 +138,15 @@ def edit_subsection(request, location): ...@@ -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 @login_required
def edit_unit(request, location): def edit_unit(request, location):
""" """
...@@ -165,7 +175,7 @@ def edit_unit(request, location): ...@@ -165,7 +175,7 @@ def edit_unit(request, location):
component_templates = defaultdict(list) component_templates = defaultdict(list)
for category in COMPONENT_TYPES: for category in COMPONENT_TYPES:
component_class = XModuleDescriptor.load_class(category) component_class = load_mixed_class(category)
# add the default template # add the default template
# TODO: Once mixins are defined per-application, rather than per-runtime, # TODO: Once mixins are defined per-application, rather than per-runtime,
# this should use a cms mixed-in class. (cpennington) # this should use a cms mixed-in class. (cpennington)
...@@ -203,7 +213,7 @@ def edit_unit(request, location): ...@@ -203,7 +213,7 @@ def edit_unit(request, location):
# class? i.e., can an advanced have more than one entry in the # class? i.e., can an advanced have more than one entry in the
# menu? one for default and others for prefilled boilerplates? # menu? one for default and others for prefilled boilerplates?
try: try:
component_class = XModuleDescriptor.load_class(category) component_class = load_mixed_class(category)
component_templates['advanced'].append(( component_templates['advanced'].append((
component_class.display_name.default or category, component_class.display_name.default or category,
......
...@@ -2,6 +2,7 @@ import logging ...@@ -2,6 +2,7 @@ import logging
import sys import sys
from functools import partial from functools import partial
from django.conf import settings
from django.http import HttpResponse, Http404, HttpResponseBadRequest, HttpResponseForbidden from django.http import HttpResponse, Http404, HttpResponseBadRequest, HttpResponseForbidden
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
...@@ -116,6 +117,7 @@ def preview_module_system(request, preview_id, descriptor): ...@@ -116,6 +117,7 @@ def preview_module_system(request, preview_id, descriptor):
user=request.user, user=request.user,
xblock_field_data=preview_field_data, xblock_field_data=preview_field_data,
can_execute_unsafe_code=(lambda: can_execute_unsafe_code(course_id)), can_execute_unsafe_code=(lambda: can_execute_unsafe_code(course_id)),
mixins=settings.XBLOCK_MIXINS,
) )
......
...@@ -169,7 +169,8 @@ class TestPeerGradingService(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -169,7 +169,8 @@ class TestPeerGradingService(ModuleStoreTestCase, LoginEnrollmentTestCase):
replace_urls=None, replace_urls=None,
xblock_field_data=lambda d: d._field_data, xblock_field_data=lambda d: d._field_data,
s3_interface=test_util_open_ended.S3_INTERFACE, 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.descriptor = peer_grading_module.PeerGradingDescriptor(self.system, field_data, ScopeIds(None, None, None, None))
self.peer_module = self.descriptor.xmodule(self.system) self.peer_module = self.descriptor.xmodule(self.system)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment