diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py index 92cced6106..d189e18216 100644 --- a/cms/djangoapps/contentstore/views.py +++ b/cms/djangoapps/contentstore/views.py @@ -69,10 +69,8 @@ log = logging.getLogger(__name__) COMPONENT_TYPES = ['customtag', 'discussion', 'html', 'problem', 'video'] -ADVANCED_COMPONENT_TYPES = { - 'advanced' : ['annotatable','combinedopenended', 'peergrading'] -} - +ADVANCED_COMPONENT_TYPES = ['annotatable','combinedopenended', 'peergrading'] +ADVANCED_COMPONENT_CATEGORY = 'advanced' ADVANCED_COMPONENT_POLICY_KEY = 'advanced_modules' # cdodge: these are categories which should not be parented, they are detached from the hierarchy @@ -288,11 +286,13 @@ def edit_unit(request, location): component_templates = defaultdict(list) - # check if there are any advanced modules specified in the course policy + # Check if there are any advanced modules specified in the course policy. These modules + # should be specified as a list of strings, where the strings are the names of the modules + # in ADVANCED_COMPONENT_TYPES that should be enabled for the course. course_metadata = CourseMetadata.fetch(course.location) course_advanced_keys = course_metadata.get(ADVANCED_COMPONENT_POLICY_KEY, []) - # check if the keys are in JSON format, or perhaps a literal python expression + # We expect the advanced keys to be a *list* of strings, but if it is a JSON-encoded string, attempt to parse it. if isinstance(course_advanced_keys, basestring): # Are you JSON? try: @@ -307,28 +307,24 @@ def edit_unit(request, location): log.error("Cannot parse course advanced policy at all: {0}".format(course_advanced_keys)) course_advanced_keys=[] - #Set component types according to course policy file - component_types = COMPONENT_TYPES + # Set component types according to course policy file + component_types = list(COMPONENT_TYPES) if isinstance(course_advanced_keys, list): - #Generate a subset of the dictionary for just needed keys course_advanced_keys = [c for c in course_advanced_keys if c in ADVANCED_COMPONENT_TYPES] - advanced_component_type_mappings = {k: ADVANCED_COMPONENT_TYPES.get(k,[]) for k in course_advanced_keys} - #Let course staff defined keys be valid - component_types+=course_advanced_keys + if len(course_advanced_keys) > 0: + component_types.append(ADVANCED_COMPONENT_CATEGORY) else: log.error("Improper format for course advanced keys! {0}".format(course_advanced_keys)) templates = modulestore().get_items(Location('i4x', 'edx', 'templates')) for template in templates: category = template.location.category - #Map subcategory to upper level category - for key in course_advanced_keys: - if category in advanced_component_type_mappings[key]: - category = key - break + + if category in course_advanced_keys: + category = ADVANCED_COMPONENT_CATEGORY if category in component_types: - #This is a hack to create categories for different xmodules + #This is a hack to create categories for different xmodules component_templates[category].append(( template.display_name, template.location.url(),