Commit e83fb3f8 by Bridger Maxwell

Added new API to xmodule(descriptor). get_children_locations and has_dynamic_children.

parent 70818f8b
...@@ -48,10 +48,8 @@ class ABTestModule(XModule): ...@@ -48,10 +48,8 @@ class ABTestModule(XModule):
def get_shared_state(self): def get_shared_state(self):
return json.dumps({'group': self.group}) return json.dumps({'group': self.group})
def displayable_items(self): def get_children_locations(self):
child_locations = self.definition['data']['group_content'][self.group] return self.definition['data']['group_content'][self.group]
children = [self.system.get_module(loc) for loc in child_locations]
return [c for c in children if c is not None]
# TODO (cpennington): Use Groups should be a first class object, rather than being # TODO (cpennington): Use Groups should be a first class object, rather than being
...@@ -158,3 +156,7 @@ class ABTestDescriptor(RawDescriptor, XmlDescriptor): ...@@ -158,3 +156,7 @@ class ABTestDescriptor(RawDescriptor, XmlDescriptor):
group_elem.append(etree.fromstring(child.export_to_xml(resource_fs))) group_elem.append(etree.fromstring(child.export_to_xml(resource_fs)))
return xml_object return xml_object
def has_dynamic_children(self):
return True
...@@ -219,7 +219,7 @@ class XModule(HTMLSnippet): ...@@ -219,7 +219,7 @@ class XModule(HTMLSnippet):
Return module instances for all the children of this module. Return module instances for all the children of this module.
''' '''
if self._loaded_children is None: if self._loaded_children is None:
child_locations = self.definition.get('children', []) child_locations = self.get_children_locations()
children = [self.system.get_module(loc) for loc in child_locations] children = [self.system.get_module(loc) for loc in child_locations]
# get_module returns None if the current user doesn't have access # get_module returns None if the current user doesn't have access
# to the location. # to the location.
...@@ -227,6 +227,21 @@ class XModule(HTMLSnippet): ...@@ -227,6 +227,21 @@ class XModule(HTMLSnippet):
return self._loaded_children return self._loaded_children
def get_children_locations(self):
'''
Returns the locations of each of child modules.
Overriding this changes the behavior of get_children and
anything that uses get_children, such as get_display_items.
This method will not instantiate the modules of the children
unless absolutely necessary, so it is cheaper to call than get_children
These children will be the same children returned by the
descriptor unless descriptor.has_dynamic_children() is true.
'''
return self.definition.get('children', [])
def get_display_items(self): def get_display_items(self):
''' '''
Returns a list of descendent module instances that will display Returns a list of descendent module instances that will display
...@@ -490,6 +505,18 @@ class XModuleDescriptor(Plugin, HTMLSnippet): ...@@ -490,6 +505,18 @@ class XModuleDescriptor(Plugin, HTMLSnippet):
metadata=self.metadata metadata=self.metadata
) )
def has_dynamic_children(self):
"""
Returns True if this descriptor has dynamic children for a given
student when the module is created.
Returns False if the children of this descriptor are the same
children that the module will return for any student.
"""
return False
# ================================= JSON PARSING =========================== # ================================= JSON PARSING ===========================
@staticmethod @staticmethod
def load_from_json(json_data, system, default_class=None): def load_from_json(json_data, system, default_class=None):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment