From 560cd9b0686007f736e4eebd74a5ae649ba6e3d1 Mon Sep 17 00:00:00 2001 From: Felix Sun Date: Tue, 2 Jul 2013 09:40:47 -0400 Subject: [PATCH] Fixed bug when user votes w/o permission - now displays a friendly error message instead of failing. Fixed bug when hinter module displays a hint, then is asked to display nothing. (Used to not update in this case.) --- .../lib/xmodule/xmodule/crowdsource_hinter.py | 2 +- .../js/src/crowdsource_hinter/display.coffee | 2 ++ common/templates/hinter_display.html | 19 ++++++++++++------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/common/lib/xmodule/xmodule/crowdsource_hinter.py b/common/lib/xmodule/xmodule/crowdsource_hinter.py index f84b366d2c..5b9c0a1899 100644 --- a/common/lib/xmodule/xmodule/crowdsource_hinter.py +++ b/common/lib/xmodule/xmodule/crowdsource_hinter.py @@ -227,7 +227,7 @@ class CrowdsourceHinterModule(CrowdsourceHinterFields, XModule): Returns key 'hint_and_votes', a list of (hint_text, #votes) pairs. """ if self.user_voted: - return json.dumps({'contents': 'Sorry, but you have already voted!'}) + return {} ans_no = int(get['answer']) hint_no = str(get['hint']) answer = self.previous_answers[ans_no][0] diff --git a/common/lib/xmodule/xmodule/js/src/crowdsource_hinter/display.coffee b/common/lib/xmodule/xmodule/js/src/crowdsource_hinter/display.coffee index f8bc6037db..72522f5b03 100644 --- a/common/lib/xmodule/xmodule/js/src/crowdsource_hinter/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/crowdsource_hinter/display.coffee @@ -72,3 +72,5 @@ class @Hinter JavascriptLoader.executeModuleScripts @el, () => @bind() @$('#previous-answer-0').css('display', 'inline') + else + @el.hide() diff --git a/common/templates/hinter_display.html b/common/templates/hinter_display.html index bc49bf18bd..6f5d6f37fb 100644 --- a/common/templates/hinter_display.html +++ b/common/templates/hinter_display.html @@ -95,13 +95,17 @@ What would you say to help someone who got this wrong answer? <%def name="show_votes()"> - Thank you for voting! -
- % for hint, votes in hint_and_votes: - ${votes} votes. - ${hint} -
- % endfor + % if hint_and_votes is UNDEFINED: + Sorry, but you've already voted! + % else: + Thank you for voting! +
+ % for hint, votes in hint_and_votes: + ${votes} votes. + ${hint} +
+ % endfor + % endif <%def name="simple_message()"> @@ -123,3 +127,4 @@ What would you say to help someone who got this wrong answer? % if op == "vote": ${show_votes()} % endif +