Commit 95ef1216 by ichuang

extend conditional module to add require_attempted

parent 1d29e1f2
...@@ -403,6 +403,10 @@ class CapaModule(XModule): ...@@ -403,6 +403,10 @@ class CapaModule(XModule):
# return self.answer_available() # return self.answer_available()
return self.lcp.done return self.lcp.done
def is_attempted(self):
# used by conditional module
return self.attempts > 0
def answer_available(self): def answer_available(self):
''' Is the user allowed to see an answer? ''' Is the user allowed to see an answer?
''' '''
......
...@@ -19,6 +19,10 @@ class ConditionalModule(XModule): ...@@ -19,6 +19,10 @@ class ConditionalModule(XModule):
<video url_name="secret_video" /> <video url_name="secret_video" />
</conditional> </conditional>
<conditional condition="require_attempted" required="tag/url_name1&tag/url_name2">
<video url_name="secret_video" />
</conditional>
''' '''
js = {'coffee': [resource_string(__name__, 'js/src/conditional/display.coffee'), js = {'coffee': [resource_string(__name__, 'js/src/conditional/display.coffee'),
...@@ -67,6 +71,18 @@ class ConditionalModule(XModule): ...@@ -67,6 +71,18 @@ class ConditionalModule(XModule):
else: else:
log.debug('conditional module: %s IS completed' % module) log.debug('conditional module: %s IS completed' % module)
return True return True
elif self.condition=='require_attempted':
# all required modules must be attempted, as determined by
# the modules .is_attempted() method
for module in self.required_modules:
if not hasattr(module, 'is_attempted'):
raise Exception('Error in conditional module: required module %s has no .is_attempted() method' % module)
if not module.is_attempted():
log.debug('conditional module: %s not completed' % module)
return False
else:
log.debug('conditional module: %s IS completed' % module)
return True
else: else:
raise Exception('Error in conditional module: unknown condition "%s"' % self.condition) raise Exception('Error in conditional module: unknown condition "%s"' % self.condition)
...@@ -128,4 +144,4 @@ class ConditionalDescriptor(SequenceDescriptor): ...@@ -128,4 +144,4 @@ class ConditionalDescriptor(SequenceDescriptor):
"""Returns a list of XModuleDescritpor instances upon which this module depends, but are """Returns a list of XModuleDescritpor instances upon which this module depends, but are
not children of this module""" not children of this module"""
return [self.system.load_item(loc) for loc in self.required_module_locations] return [self.system.load_item(loc) for loc in self.required_module_locations]
\ No newline at end of file
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