From 5f988fd916fb8052a6ff0257e9b01bcc710ace56 Mon Sep 17 00:00:00 2001 From: Alexander Kryklia Date: Thu, 13 Dec 2012 14:13:52 +0200 Subject: [PATCH] sliders and inputs are now optional --- common/lib/xmodule/xmodule/gst_module.py | 113 ++++++----------------- 1 file changed, 29 insertions(+), 84 deletions(-) diff --git a/common/lib/xmodule/xmodule/gst_module.py b/common/lib/xmodule/xmodule/gst_module.py index f0c3d0b7e6..74cc70e076 100644 --- a/common/lib/xmodule/xmodule/gst_module.py +++ b/common/lib/xmodule/xmodule/gst_module.py @@ -41,65 +41,8 @@ class GraphicalSliderToolModule(XModule): def __init__(self, system, location, definition, descriptor, instance_state=None, shared_state=None, **kwargs): """ - Definition should have.... - sliders, text, module + For XML file format please look at documentation. - Sample file: - - - - - -

Graphic slider tool html.

-

Can include 'input', 'slider' and 'plot' tags. - They will be replaced by proper number, slider and plot - widgets.

- For example: $slider a$, second $slider b$, - number $input a$, and, plot: - $plot$ - - -
- - - - - - - - - - - - - - - - - - - -10, 10 - - 60 - - -9, 1, 9 - -9, 1, 9 - - - - - - -
-
-
""" XModule.__init__(self, system, location, definition, descriptor, instance_state, shared_state, **kwargs) @@ -130,37 +73,39 @@ class GraphicalSliderToolModule(XModule): style="width: 600px; height: 600px; padding: 0px; position: relative;">This is plot' html_string = html_string.replace('$plot$', plot_div) - # substitute sliders - sliders = json.loads(self.configuration_json)['root']['sliders']['slider'] - if type(sliders) == dict: - sliders = [sliders] - vars = [x['@var'] for x in sliders] + # substitute sliders if we have them + if json.loads(self.configuration_json)['root'].get('sliders'): + sliders = json.loads(self.configuration_json)['root']['sliders']['slider'] + if type(sliders) == dict: + sliders = [sliders] + vars = [x['@var'] for x in sliders] - slider_div = '' + slider_div = '' - for var in vars: - html_string = re.sub(r'\$slider\s+' + var + r'\$', - slider_div.format(element_class=self.html_class, - element_id=self.html_id, - var=var), - html_string, flags=re.IGNORECASE | re.UNICODE) + for var in vars: + html_string = re.sub(r'\$slider\s+' + var + r'\$', + slider_div.format(element_class=self.html_class, + element_id=self.html_id, + var=var), + html_string, flags=re.IGNORECASE | re.UNICODE) - # substitute numbers - inputs = json.loads(self.configuration_json)['root']['inputs']['input'] - if type(inputs) == dict: - inputs = [inputs] - vars = [x['@var'] for x in inputs] + # substitute numbers if we have them + if json.loads(self.configuration_json)['root'].get('inputs'): + inputs = json.loads(self.configuration_json)['root']['inputs']['input'] + if type(inputs) == dict: + inputs = [inputs] + vars = [x['@var'] for x in inputs] - input_div = '' + input_div = '' - for var in vars: - html_string = re.sub(r'\$input\s+' + var + r'\$', - input_div.format(element_class=self.html_class, - element_id=self.html_id, - var=var), - html_string, flags=re.IGNORECASE | re.UNICODE) + for var in vars: + html_string = re.sub(r'\$input\s+' + var + r'\$', + input_div.format(element_class=self.html_class, + element_id=self.html_id, + var=var), + html_string, flags=re.IGNORECASE | re.UNICODE) # import ipdb; ipdb.set_trace() return html_string