diff --git a/common/lib/xmodule/xmodule/crowdsource_hinter.py b/common/lib/xmodule/xmodule/crowdsource_hinter.py
index bf3c83b719..da6ae989e3 100644
--- a/common/lib/xmodule/xmodule/crowdsource_hinter.py
+++ b/common/lib/xmodule/xmodule/crowdsource_hinter.py
@@ -106,13 +106,20 @@ class CrowdsourceHinterModule(CrowdsourceHinterFields, XModule):
This is the landing method for AJAX calls.
'''
if dispatch == 'get_hint':
- return self.get_hint(get)
+ out = self.get_hint(get)
if dispatch == 'get_feedback':
- return self.get_feedback(get)
+ out = self.get_feedback(get)
if dispatch == 'vote':
- return self.tally_vote(get)
+ out = self.tally_vote(get)
if dispatch == 'submit_hint':
- return self.submit_hint(get)
+ out = self.submit_hint(get)
+
+ if out == None:
+ out = {'op': 'empty'}
+ else:
+ out.update({'op': dispatch})
+ return json.dumps({'contents': self.system.render_template('hinter_display.html', out)})
+
def get_hint(self, get):
'''
@@ -123,7 +130,7 @@ class CrowdsourceHinterModule(CrowdsourceHinterFields, XModule):
if (answer not in self.hints) or (len(self.hints[answer]) == 0):
# No hints to give. Return.
self.previous_answers += [[answer, [None, None, None]]]
- return json.dumps({'contents': ' '})
+ return
# Get the top hint, plus two random hints.
n_hints = len(self.hints[answer])
best_hint_index = max(self.hints[answer], key=lambda key: self.hints[answer][key][1])
@@ -145,8 +152,11 @@ class CrowdsourceHinterModule(CrowdsourceHinterFields, XModule):
rand_hint_1 = rand_hint_1[0]
rand_hint_2 = rand_hint_2[0]
self.previous_answers += [(answer, (best_hint_index, hint_index_1, hint_index_2))]
- hint_text = best_hint + '
' + rand_hint_1 + '
' + rand_hint_2
- return json.dumps({'contents': hint_text})
+
+ return {'best_hint': best_hint,
+ 'rand_hint_1': rand_hint_1,
+ 'rand_hint_2': rand_hint_2,
+ 'answer': answer}
def get_feedback(self, get):
'''
@@ -154,55 +164,33 @@ class CrowdsourceHinterModule(CrowdsourceHinterFields, XModule):
'''
# The student got it right.
# Did he submit at least one wrong answer?
- out = ' '
+ out = ''
if len(self.previous_answers) == 0:
# No. Nothing to do here.
- return json.dumps({'contents': out})
+ return
# Make a hint-voting interface for each wrong answer. The student will only
# be allowed to make one vote / submission, but he can choose which wrong answer
# he wants to look at.
- pretty_answers = []
+ # index_to_hints[previous answer #] = [(hint text, hint pk), + ]
+ index_to_hints = {}
+ # index_to_answer[previous answer #] = answer text
+ index_to_answer = {}
+
for i in xrange(len(self.previous_answers)):
answer, hints_offered = self.previous_answers[i]
- pretty_answers.append(answer)
- # If there are previous hints for this answer, ask the student to vote on one.
- out += '