Commit 4b148f9a by Alexander Kryklia

working import

parent 2625d7cb
...@@ -32,6 +32,7 @@ class ConditionalModule(XModule): ...@@ -32,6 +32,7 @@ class ConditionalModule(XModule):
# xml_object = String(scope=Scope.content) # xml_object = String(scope=Scope.content)
contents = String(scope=Scope.content) contents = String(scope=Scope.content)
show_modules = String(scope=Scope.content)
def _get_required_modules(self): def _get_required_modules(self):
self.required_modules = [] self.required_modules = []
...@@ -84,6 +85,16 @@ class ConditionalModule(XModule): ...@@ -84,6 +85,16 @@ class ConditionalModule(XModule):
'ajax_url': self.system.ajax_url, 'ajax_url': self.system.ajax_url,
}) })
def _get_modules_to_show(self):
to_show = [tuple(x.strip().split('/',1)) for x in self.show_modules.split(';')]
self.modules_to_show = []
for (tag, name) in to_show:
loc = self.location.dict()
loc['category'] = tag
loc['name'] = name
self.modules_to_show.append(Location(loc))
def handle_ajax(self, dispatch, post): def handle_ajax(self, dispatch, post):
''' '''
This is called by courseware.moduleodule_render, to handle an AJAX call. This is called by courseware.moduleodule_render, to handle an AJAX call.
...@@ -98,9 +109,11 @@ class ConditionalModule(XModule): ...@@ -98,9 +109,11 @@ class ConditionalModule(XModule):
if self.contents is None: if self.contents is None:
import ipdb; ipdb.set_trace() import ipdb; ipdb.set_trace()
# self.contents = [child.get_html() for child in self.get_display_items()] # self.contents = [child.get_html() for child in self.get_display_items()]
self.contents = [self.system.get_module(child_descriptor.location).get_html() self.contents = [self.system.get_module(x).get_html() for x in self.modules_to_show]
self.contents += [self.system.get_module(child_descriptor.location).get_html()
for child_descriptor in self.descriptor.get_children()] for child_descriptor in self.descriptor.get_children()]
html = self.contents html = self.contents
#log.debug('rendered conditional module %s' % str(self.location)) #log.debug('rendered conditional module %s' % str(self.location))
return json.dumps({'html': html}) return json.dumps({'html': html})
...@@ -114,16 +127,19 @@ class ConditionalDescriptor(SequenceDescriptor): ...@@ -114,16 +127,19 @@ class ConditionalDescriptor(SequenceDescriptor):
stores_state = True stores_state = True
has_score = False has_score = False
show_modules = String(scope=Scope.content)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(ConditionalDescriptor, self).__init__(*args, **kwargs) super(ConditionalDescriptor, self).__init__(*args, **kwargs)
# import ipdb; ipdb.set_trace() # import ipdb; ipdb.set_trace()
required_module_list = [tuple(x.strip().split('/',1)) for x in self.xml_attributes.get('required','').split(';')] required_module_list = [(x.strip().split('/',5)[4:6]) for x in self.xml_attributes.get('source','').split(';')]
self.required_module_locations = [] self.required_module_locations = []
for (tag, name) in required_module_list: for (tag, name) in required_module_list:
loc = self.location.dict() loc = self.location.dict()
loc['category'] = tag loc['category'] = tag
loc['name'] = name loc['name'] = name
self.required_module_locations.append(Location(loc)) self.required_module_locations.append(Location(loc))
# import ipdb; ipdb.set_trace()
log.debug('ConditionalDescriptor required_module_locations=%s' % self.required_module_locations) log.debug('ConditionalDescriptor required_module_locations=%s' % self.required_module_locations)
def get_required_module_descriptors(self): def get_required_module_descriptors(self):
...@@ -133,9 +149,9 @@ class ConditionalDescriptor(SequenceDescriptor): ...@@ -133,9 +149,9 @@ class ConditionalDescriptor(SequenceDescriptor):
@classmethod @classmethod
def definition_from_xml(cls, xml_object, system): def definition_from_xml(cls, xml_object, system):
# import ipdb; ipdb.set_trace()
children = [] children = []
for child in xml_object: for child in xml_object:
if child.tag != 'show':
try: try:
children.append(system.process_xml(etree.tostring(child)).location.url()) children.append(system.process_xml(etree.tostring(child)).location.url())
except Exception, e: except Exception, e:
...@@ -143,8 +159,9 @@ class ConditionalDescriptor(SequenceDescriptor): ...@@ -143,8 +159,9 @@ class ConditionalDescriptor(SequenceDescriptor):
if system.error_tracker is not None: if system.error_tracker is not None:
system.error_tracker("ERROR: " + str(e)) system.error_tracker("ERROR: " + str(e))
continue continue
# import ipdb; ipdb.set_trace() else:
return {}, children cls.show_modules = child.get('source')
return {'show_modules':''}, children
def definition_to_xml(self, resource_fs): def definition_to_xml(self, resource_fs):
xml_object = etree.Element('sequential') xml_object = etree.Element('sequential')
......
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