Add ResourceTemplates to XBLOCK_MIXINS so it’s applied to all CMS XBlocks at runtime instead of being directly inherited. This keeps the Studio-only feature in edx-platform (where it belongs), while still making it available to built-in and extracted XBlocks. When we extract built-in blocks from the platform, they will not be able to inherit ResourcesTemplates directly; they will get it from XBLOCK_MIXINS. So, we also needed to update a few template-related tests to use the mixed block class (or an instance of it) rather than the unmixed base class, because the unmixed base classes will soon be extracted and thus lack ResourceTemplates. Related to https://github.com/openedx/edx-platform/issues/34827
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
"""
|
|
This module handles loading xmodule templates
|
|
These templates are used by the CMS to provide content that overrides xmodule defaults for
|
|
samples.
|
|
|
|
``Template``s are defined in x_module. They contain 2 attributes:
|
|
:metadata: A dictionary with the template metadata
|
|
:data: A JSON value that defines the template content
|
|
"""
|
|
|
|
# should this move to cms since it's really only for module crud?
|
|
|
|
|
|
import logging
|
|
from collections import defaultdict
|
|
|
|
from xblock.core import XBlock
|
|
|
|
from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
def all_templates():
|
|
"""
|
|
Returns all templates for enabled modules, grouped by block type
|
|
"""
|
|
# TODO use memcache to memoize w/ expiration
|
|
templates = defaultdict(list)
|
|
course = CourseFactory.create()
|
|
|
|
for category, _ in XBlock.load_classes():
|
|
loaded_block = BlockFactory.create(category=category, parent_location=course.location)
|
|
if not hasattr(loaded_block, 'templates'):
|
|
continue
|
|
templates[category] = loaded_block.templates()
|
|
|
|
return templates
|