Commit 6deeb602 by Vasyl Nakvasiuk

update template for word_cloud, refactor empty json answer

parent ed23aef6
...@@ -149,7 +149,7 @@ function WordCloudMain(el) { ...@@ -149,7 +149,7 @@ function WordCloudMain(el) {
return; return;
} }
if (this.configJson.hasOwnProperty('status') && this.configJson.status === 'success') { if (this.configJson.submitted) {
this.showWordCloud(this.configJson); this.showWordCloud(this.configJson);
return; return;
......
...@@ -72,18 +72,21 @@ class ConditionalModuleTest(LogicTest): ...@@ -72,18 +72,21 @@ class ConditionalModuleTest(LogicTest):
class WordCloudModuleTest(LogicTest): class WordCloudModuleTest(LogicTest):
descriptor_class = WordCloudDescriptor descriptor_class = WordCloudDescriptor
raw_model_data = { raw_model_data = {
'all_words': {'Yes': 1, 'Dont_know': 0, 'No': 0}, 'all_words': {'cat': 10, 'dog': 5, 'mom': 1, 'dad': 2},
'top_words': {'Yes': 1, 'Dont_know': 0, 'No': 0}, 'top_words': {'cat': 10, 'dog': 5, 'dad': 2},
'submitted': False, 'submitted': False,
'student_words': ['mom', 'dad', 'cat'] 'student_words': ['mom', 'dad', 'cat']
} }
def test_bad_ajax_request(self): def test_bad_ajax_request(self):
# TODO: move top global test.
response = self.ajax_request('bad_dispatch', {}) response = self.ajax_request('bad_dispatch', {})
self.assertDictEqual(response, { self.assertDictEqual(response, {
'status': 'fail', 'status': 'fail',
'error': 'Unknown Command!' 'error': 'Unknown Command!'
}) })
# TODO
# def test_good_ajax_request(self): # def test_good_ajax_request(self):
# response = self.ajax_request('submit', {}) # response = self.ajax_request('submit', {})
...@@ -27,7 +27,7 @@ class WordCloudFields(object): ...@@ -27,7 +27,7 @@ class WordCloudFields(object):
# Name of poll to use in links to this poll # Name of poll to use in links to this poll
display_name = String(help="Display name for this module", scope=Scope.settings) 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_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) 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=[]) student_words= List(help="Student answer", scope=Scope.user_state, default=[])
...@@ -53,6 +53,7 @@ class WordCloudModule(WordCloudFields, XModule): ...@@ -53,6 +53,7 @@ class WordCloudModule(WordCloudFields, XModule):
if self.submitted: if self.submitted:
return json.dumps({ return json.dumps({
'status': 'success', 'status': 'success',
'submitted': True,
'student_words': { 'student_words': {
word:self.all_words[word] for word:self.all_words[word] for
word in self.student_words word in self.student_words
...@@ -61,7 +62,13 @@ class WordCloudModule(WordCloudFields, XModule): ...@@ -61,7 +62,13 @@ class WordCloudModule(WordCloudFields, XModule):
'top_words': self.prepare_words(self.top_words) 'top_words': self.prepare_words(self.top_words)
}) })
else: else:
return json.dumps({}) return json.dumps({
'status': 'success',
'submitted': False,
'student_words': {},
'total_count': 0,
'top_words': {}
})
def good_word(self, word): def good_word(self, word):
"""Convert raw word to suitable word.""" """Convert raw word to suitable word."""
...@@ -102,7 +109,6 @@ class WordCloudModule(WordCloudFields, XModule): ...@@ -102,7 +109,6 @@ class WordCloudModule(WordCloudFields, XModule):
}) })
# Student words from client. # Student words from client.
raw_student_words = post.getlist('student_words[]') raw_student_words = post.getlist('student_words[]')
student_words = filter(None, map(self.good_word, raw_student_words)) student_words = filter(None, map(self.good_word, raw_student_words))
...@@ -141,6 +147,7 @@ class WordCloudModule(WordCloudFields, XModule): ...@@ -141,6 +147,7 @@ class WordCloudModule(WordCloudFields, XModule):
'ajax_url': self.system.ajax_url, 'ajax_url': self.system.ajax_url,
'configuration_json': self.get_state(), 'configuration_json': self.get_state(),
'num_inputs': int(self.num_inputs), 'num_inputs': int(self.num_inputs),
'submitted': self.submitted
} }
self.content = self.system.render_template('word_cloud.html', params) self.content = self.system.render_template('word_cloud.html', params)
return self.content return self.content
......
...@@ -6,7 +6,12 @@ ...@@ -6,7 +6,12 @@
<section id="input-cloud-section"> <section id="input-cloud-section">
% for row in range(num_inputs): % for row in range(num_inputs):
<input class="input-cloud" type="text" size="40" /> <input
class="input-cloud"
${'style="display: none;"' if submitted else ''}
type="text"
size="40"
/>
% endfor % endfor
<section class="action"> <section class="action">
......
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