Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions cms/djangoapps/contentstore/tests/test_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
from xmodule import templates
from xmodule.capa_block import ProblemBlock
from xmodule.course_block import CourseBlock
from xmodule.html_block import HtmlBlock
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.exceptions import DuplicateCourseError
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory
from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory
from xmodule.seq_block import SequenceBlock


Expand Down Expand Up @@ -40,11 +39,14 @@ def test_get_templates(self):
self.assertRegex(dropdown['data'], r'<problem>\s*<optionresponse>\s*<p>.*dropdown problems.*')

def test_get_some_templates(self):
course = CourseFactory.create()
htmlblock = BlockFactory.create(category="html", parent_location=course.location)

self.assertEqual(len(SequenceBlock.templates()), 0)
self.assertGreater(len(HtmlBlock.templates()), 0)
self.assertGreater(len(htmlblock.templates()), 0)
self.assertIsNone(SequenceBlock.get_template('doesntexist.yaml'))
self.assertIsNone(HtmlBlock.get_template('doesntexist.yaml'))
self.assertIsNotNone(HtmlBlock.get_template('announcement.yaml'))
self.assertIsNone(htmlblock.get_template('doesntexist.yaml'))
self.assertIsNotNone(htmlblock.get_template('announcement.yaml'))

def test_factories(self):
test_course = CourseFactory.create(
Expand Down
5 changes: 3 additions & 2 deletions cms/djangoapps/contentstore/views/tests/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from xblock.runtime import DictKeyValueStore, KvsFieldData
from xblock.test.tools import TestRuntime
from xblock.validation import ValidationMessage
from xmodule.capa_block import ProblemBlock
from xmodule.course_block import DEFAULT_START_DATE
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore
Expand Down Expand Up @@ -619,7 +618,9 @@ def test_create_nicely(self):
prob_usage_key = self.response_usage_key(resp)
problem = self.get_item_from_modulestore(prob_usage_key)
# check against the template
template = ProblemBlock.get_template(template_id)
course = CourseFactory.create()
problem_block = BlockFactory.create(category="problem", parent_location=course.location)
template = problem_block.get_template(template_id)
self.assertEqual(problem.data, template["data"])
self.assertEqual(problem.display_name, template["metadata"]["display_name"])
self.assertEqual(problem.markdown, template["metadata"]["markdown"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ def create_xblock(parent_locator, user, category, display_name, boilerplate=None
data = None
template_id = boilerplate
if template_id:
clz = parent.runtime.load_block_type(category)
if clz is not None:
template = clz.get_template(template_id)
base_clz = parent.runtime.load_block_type(category)
dynamic_clz = parent.runtime.mixologist.mix(base_clz)
if dynamic_clz is not None:
template = dynamic_clz.get_template(template_id)
if template is not None:
metadata = template.get('metadata', {})
data = template.get('data')
Expand Down
3 changes: 2 additions & 1 deletion cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@

# Import after sys.path fixup
from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.x_module import XModuleMixin
from xmodule.x_module import XModuleMixin, ResourceTemplates

# These are the Mixins that will be added to every Blocklike upon instantiation.
# DO NOT EXPAND THIS LIST!! We want it eventually to be EMPTY. Why? Because dynamically adding functions/behaviors to
Expand All @@ -841,6 +841,7 @@
# (b) refactor their functionality out of the Blocklike objects and into the edx-platform block runtimes.
LmsBlockMixin,
InheritanceMixin,
ResourceTemplates,
XModuleMixin,
EditInfoMixin,
AuthoringMixin,
Expand Down
11 changes: 8 additions & 3 deletions xmodule/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

from xblock.core import XBlock

from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory

log = logging.getLogger(__name__)


Expand All @@ -25,9 +27,12 @@ def all_templates():
"""
# TODO use memcache to memoize w/ expiration
templates = defaultdict(list)
for category, block in XBlock.load_classes():
if not hasattr(block, 'templates'):
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] = block.templates()
templates[category] = loaded_block.templates()

return templates
Loading