From 6deeb60278ee07a6bdbec371ea1a5bb8739cc43c Mon Sep 17 00:00:00 2001 From: Vasyl Nakvasiuk Date: Wed, 10 Apr 2013 17:41:18 +0300 Subject: [PATCH] update template for word_cloud, refactor empty json answer --- .../xmodule/js/src/word_cloud/word_cloud_main.js | 2 +- common/lib/xmodule/xmodule/tests/test_logic.py | 13 ++++++++----- common/lib/xmodule/xmodule/word_cloud_module.py | 13 ++++++++++--- lms/templates/word_cloud.html | 7 ++++++- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/word_cloud/word_cloud_main.js b/common/lib/xmodule/xmodule/js/src/word_cloud/word_cloud_main.js index 54b68e9430..35df8d5c81 100644 --- a/common/lib/xmodule/xmodule/js/src/word_cloud/word_cloud_main.js +++ b/common/lib/xmodule/xmodule/js/src/word_cloud/word_cloud_main.js @@ -149,7 +149,7 @@ function WordCloudMain(el) { return; } - if (this.configJson.hasOwnProperty('status') && this.configJson.status === 'success') { + if (this.configJson.submitted) { this.showWordCloud(this.configJson); return; diff --git a/common/lib/xmodule/xmodule/tests/test_logic.py b/common/lib/xmodule/xmodule/tests/test_logic.py index ebe1e93d06..b29c2f2593 100644 --- a/common/lib/xmodule/xmodule/tests/test_logic.py +++ b/common/lib/xmodule/xmodule/tests/test_logic.py @@ -72,18 +72,21 @@ class ConditionalModuleTest(LogicTest): class WordCloudModuleTest(LogicTest): descriptor_class = WordCloudDescriptor raw_model_data = { - 'all_words': {'Yes': 1, 'Dont_know': 0, 'No': 0}, - 'top_words': {'Yes': 1, 'Dont_know': 0, 'No': 0}, + 'all_words': {'cat': 10, 'dog': 5, 'mom': 1, 'dad': 2}, + 'top_words': {'cat': 10, 'dog': 5, 'dad': 2}, 'submitted': False, 'student_words': ['mom', 'dad', 'cat'] } def test_bad_ajax_request(self): + + # TODO: move top global test. response = self.ajax_request('bad_dispatch', {}) self.assertDictEqual(response, { - 'status': 'fail', - 'error': 'Unknown Command!' - }) + 'status': 'fail', + 'error': 'Unknown Command!' + }) + # TODO # def test_good_ajax_request(self): # response = self.ajax_request('submit', {}) diff --git a/common/lib/xmodule/xmodule/word_cloud_module.py b/common/lib/xmodule/xmodule/word_cloud_module.py index 19b20ad1fd..896c85fa04 100644 --- a/common/lib/xmodule/xmodule/word_cloud_module.py +++ b/common/lib/xmodule/xmodule/word_cloud_module.py @@ -27,7 +27,7 @@ class WordCloudFields(object): # Name of poll to use in links to this poll display_name = String(help="Display name for this module", scope=Scope.settings) num_inputs = Integer(help="Number of inputs", scope=Scope.settings, default=5) - num_top_words = Integer(help="TODO", scope=Scope.settings, default=250) + num_top_words = Integer(help="Number of max words, which will be displayed.", scope=Scope.settings, default=250) submitted = Boolean(help="Whether this student has posted words to the cloud", scope=Scope.user_state, default=False) student_words= List(help="Student answer", scope=Scope.user_state, default=[]) @@ -53,6 +53,7 @@ class WordCloudModule(WordCloudFields, XModule): if self.submitted: return json.dumps({ 'status': 'success', + 'submitted': True, 'student_words': { word:self.all_words[word] for word in self.student_words @@ -61,7 +62,13 @@ class WordCloudModule(WordCloudFields, XModule): 'top_words': self.prepare_words(self.top_words) }) else: - return json.dumps({}) + return json.dumps({ + 'status': 'success', + 'submitted': False, + 'student_words': {}, + 'total_count': 0, + 'top_words': {} + }) def good_word(self, word): """Convert raw word to suitable word.""" @@ -102,7 +109,6 @@ class WordCloudModule(WordCloudFields, XModule): }) # Student words from client. - raw_student_words = post.getlist('student_words[]') student_words = filter(None, map(self.good_word, raw_student_words)) @@ -141,6 +147,7 @@ class WordCloudModule(WordCloudFields, XModule): 'ajax_url': self.system.ajax_url, 'configuration_json': self.get_state(), 'num_inputs': int(self.num_inputs), + 'submitted': self.submitted } self.content = self.system.render_template('word_cloud.html', params) return self.content diff --git a/lms/templates/word_cloud.html b/lms/templates/word_cloud.html index c2d1459063..ff3c728706 100644 --- a/lms/templates/word_cloud.html +++ b/lms/templates/word_cloud.html @@ -6,7 +6,12 @@
% for row in range(num_inputs): - + % endfor