Studio render XBlockAside views
PLAT-280
This commit is contained in:
@@ -45,7 +45,7 @@ from contentstore.views.helpers import is_unit, xblock_studio_url, xblock_primar
|
||||
from contentstore.views.preview import get_preview_fragment
|
||||
from edxmako.shortcuts import render_to_string
|
||||
from models.settings.course_grading import CourseGradingModel
|
||||
from cms.lib.xblock.runtime import handler_url, local_resource_url, applicable_aside_types
|
||||
from cms.lib.xblock.runtime import handler_url, local_resource_url
|
||||
from opaque_keys.edx.keys import UsageKey, CourseKey
|
||||
|
||||
__all__ = ['orphan_handler', 'xblock_handler', 'xblock_view_handler', 'xblock_outline_handler']
|
||||
@@ -64,7 +64,6 @@ ALWAYS = lambda x: True
|
||||
# TODO: Remove this code when Runtimes are no longer created by modulestores
|
||||
xmodule.x_module.descriptor_global_handler_url = handler_url
|
||||
xmodule.x_module.descriptor_global_local_resource_url = local_resource_url
|
||||
xmodule.x_module.descriptor_global_applicable_aside_types = applicable_aside_types
|
||||
|
||||
|
||||
def hash_resource(resource):
|
||||
|
||||
@@ -87,7 +87,7 @@ class PreviewModuleSystem(ModuleSystem): # pylint: disable=abstract-method
|
||||
|
||||
def handler_url(self, block, handler_name, suffix='', query='', thirdparty=False):
|
||||
return reverse('preview_handler', kwargs={
|
||||
'usage_key_string': unicode(block.location),
|
||||
'usage_key_string': unicode(block.scope_ids.usage_id),
|
||||
'handler': handler_name,
|
||||
'suffix': suffix,
|
||||
}) + '?' + query
|
||||
@@ -96,8 +96,14 @@ class PreviewModuleSystem(ModuleSystem): # pylint: disable=abstract-method
|
||||
return local_resource_url(block, uri)
|
||||
|
||||
def applicable_aside_types(self, block):
|
||||
# TODO: Implement this to enable XBlockAsides on previews in Studio
|
||||
return []
|
||||
"""
|
||||
Remove acid_aside
|
||||
"""
|
||||
return [
|
||||
aside_type
|
||||
for aside_type in super(PreviewModuleSystem, self).applicable_aside_types(block)
|
||||
if aside_type != 'acid_aside'
|
||||
]
|
||||
|
||||
|
||||
class StudioUserService(object):
|
||||
|
||||
@@ -9,6 +9,10 @@ from student.tests.factories import UserFactory
|
||||
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
|
||||
|
||||
from contentstore.views.preview import get_preview_fragment
|
||||
from xmodule.modulestore import ModuleStoreEnum
|
||||
from xblock.core import XBlockAside
|
||||
from xmodule.modulestore.tests.test_asides import AsideTestType
|
||||
import re
|
||||
|
||||
|
||||
class GetPreviewHtmlTestCase(TestCase):
|
||||
@@ -19,6 +23,7 @@ class GetPreviewHtmlTestCase(TestCase):
|
||||
get_preview_fragment via the xblock RESTful API.
|
||||
"""
|
||||
|
||||
@XBlockAside.register_temp_plugin(AsideTestType, 'test_aside')
|
||||
def test_preview_fragment(self):
|
||||
"""
|
||||
Test for calling get_preview_html.
|
||||
@@ -26,7 +31,7 @@ class GetPreviewHtmlTestCase(TestCase):
|
||||
This test used to be specifically about Locators (ensuring that they did not
|
||||
get translated to Locations). The test now has questionable value.
|
||||
"""
|
||||
course = CourseFactory.create()
|
||||
course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split)
|
||||
html = ItemFactory.create(
|
||||
parent_location=course.location,
|
||||
category="html",
|
||||
@@ -45,9 +50,13 @@ class GetPreviewHtmlTestCase(TestCase):
|
||||
html = get_preview_fragment(request, html, context).content
|
||||
|
||||
# Verify student view html is returned, and the usage ID is as expected.
|
||||
html_pattern = unicode(course.id.make_usage_key('html', 'html_')).replace('html_', r'html_[0-9]*')
|
||||
html_pattern = re.escape(unicode(course.id.make_usage_key('html', 'replaceme'))).replace('replaceme', r'html_[0-9]*')
|
||||
self.assertRegexpMatches(
|
||||
html,
|
||||
'data-usage-id="{}"'.format(html_pattern)
|
||||
)
|
||||
self.assertRegexpMatches(html, '<html>foobar</html>')
|
||||
self.assertRegexpMatches(html, r"data-block-type=[\"\']test_aside[\"\']")
|
||||
self.assertRegexpMatches(html, "Aside rendered")
|
||||
# Now ensure the acid_aside is not in the result
|
||||
self.assertNotRegexpMatches(html, r"data-block-type=[\"\']acid_aside[\"\']")
|
||||
|
||||
@@ -33,11 +33,3 @@ def local_resource_url(block, uri):
|
||||
'block_type': block.scope_ids.block_type,
|
||||
'uri': uri,
|
||||
})
|
||||
|
||||
|
||||
def applicable_aside_types(block): # pylint: disable=unused-argument
|
||||
"""
|
||||
Get the application-relative list of aside types for this type of block.
|
||||
"""
|
||||
# TODO: Implement this method to make XBlockAsides for editing views in Studio
|
||||
return []
|
||||
|
||||
Reference in New Issue
Block a user