Commit 67ada1fb by Vasyl Nakvasiuk

add docstrings

parent f903bc3c
# -*- coding: utf-8 -*- """Conditional module is the xmodule, which you can use for disabling
some xmodules by conditions.
"""
import json import json
import logging import logging
...@@ -20,7 +22,8 @@ class ConditionalModule(XModule): ...@@ -20,7 +22,8 @@ class ConditionalModule(XModule):
Example: Example:
<conditional condition="require_completed" required="tag/url_name1&tag/url_name2"> <conditional sources="i4x://.../problem_1" completed="True">
<show sources="i4x://.../test_6; i4x://.../Avi_resources"/>
<video url_name="secret_video" /> <video url_name="secret_video" />
</conditional> </conditional>
...@@ -37,7 +40,9 @@ class ConditionalModule(XModule): ...@@ -37,7 +40,9 @@ class ConditionalModule(XModule):
contents = String(scope=Scope.content) contents = String(scope=Scope.content)
# TODO # Map
# key: <tag attribute in xml>
# value: <name of module attribute>
conditions_map = { conditions_map = {
'poll_answer': 'poll_answer', # poll_question attr 'poll_answer': 'poll_answer', # poll_question attr
'compeleted': 'is_competed', # capa_problem attr 'compeleted': 'is_competed', # capa_problem attr
...@@ -45,7 +50,7 @@ class ConditionalModule(XModule): ...@@ -45,7 +50,7 @@ class ConditionalModule(XModule):
} }
def _get_condition(self): def _get_condition(self):
# get first valid contition # Get first valid condition.
for xml_attr, attr_name in self.conditions_map.iteritems(): for xml_attr, attr_name in self.conditions_map.iteritems():
xml_value = self.descriptor.xml_attributes.get(xml_attr) xml_value = self.descriptor.xml_attributes.get(xml_attr)
if xml_value: if xml_value:
...@@ -80,17 +85,19 @@ class ConditionalModule(XModule): ...@@ -80,17 +85,19 @@ class ConditionalModule(XModule):
}) })
def handle_ajax(self, dispatch, post): def handle_ajax(self, dispatch, post):
''' """This is called by courseware.moduleodule_render, to handle
This is called by courseware.moduleodule_render, to handle an AJAX call. an AJAX call.
''' """
if not self.is_condition_satisfied(): if not self.is_condition_satisfied():
context = {'module': self} context = {'module': self}
html = self.system.render_template('conditional_module.html', context) html = self.system.render_template('conditional_module.html',
context)
return json.dumps({'html': [html]}) return json.dumps({'html': [html]})
if self.contents is None: if self.contents is None:
self.contents = [self.system.get_module(child_descriptor.location).get_html() self.contents = [self.system.get_module(child_descriptor.location
for child_descriptor in self.descriptor.get_children()] ).get_html()
for child_descriptor in self.descriptor.get_children()]
html = self.contents html = self.contents
return json.dumps({'html': html}) return json.dumps({'html': html})
......
...@@ -6,7 +6,6 @@ If student does not yet anwered - Question with set of choices. ...@@ -6,7 +6,6 @@ If student does not yet anwered - Question with set of choices.
If student have answered - Question with statistics for each answers. If student have answered - Question with statistics for each answers.
Student can't change his answer. Student can't change his answer.
""" """
import cgi import cgi
......
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