Instead, we use XModule field default values when creating an empty XModule. Driven by this use case, we also allow for XModules to be created in memory without being persisted to the database at all. This necessitates a change to the Modulestore api, replacing clone_item with create_draft and save_xmodule.
30 lines
865 B
Python
30 lines
865 B
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 .x_module import XModuleDescriptor
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
def all_templates():
|
|
"""
|
|
Returns all templates for enabled modules, grouped by descriptor type
|
|
"""
|
|
# TODO use memcache to memoize w/ expiration
|
|
templates = defaultdict(list)
|
|
for category, descriptor in XModuleDescriptor.load_classes():
|
|
templates[category] = descriptor.templates()
|
|
|
|
return templates
|