Commit fd9a6500 by Sola Committed by Piotr Mitros

fixed student hint submission, squashed bug

parent 75ecb3a6
...@@ -362,29 +362,26 @@ class CrowdXBlock(XBlock): ...@@ -362,29 +362,26 @@ class CrowdXBlock(XBlock):
""" """
submission = data['submission'].replace('ddeecciimmaallppooiinntt', '.') submission = data['submission'].replace('ddeecciimmaallppooiinntt', '.')
answer = data['answer'].replace('ddeecciimmaallppooiinntt', '.') answer = data['answer'].replace('ddeecciimmaallppooiinntt', '.')
for answer_keys in self.hint_database: if str(submission) not in self.hint_database[str(answer)]:
if str(answer_keys) == str(answer): temporary_dictionary = str(self.hint_database[str(answer)])
# find the answer for which a hint is being submitted temporary_dictionary = (ast.literal_eval(temporary_dictionary))
if str(submission) not in self.hint_database[str(answer_keys)]: temporary_dictionary.update({submission: 0})
temporary_dictionary = str(self.hint_database[str(answer_keys)]) # once again, manipulating temporary_dictionary and setting
temporary_dictionary = (ast.literal_eval(temporary_dictionary)) # self.hint_database equal to it due to being unable to directly
temporary_dictionary.update({submission: 0}) # edit self.hint_databse. Most likely scope error
# once again, manipulating temporary_dictionary and setting self.hint_database[str(answer)] = temporary_dictionary
# self.hint_database equal to it due to being unable to directly return
# edit self.hint_databse. Most likely scope error else:
self.hint_database[str(answer_keys)] = temporary_dictionary # if the hint exists already, simply upvote the previously entered hint
return if str(submission) in self.DefaultHints:
else: self.DefaultHints[str(submission)] += int(1)
# if the hint exists already, simply upvote the previously entered hint return
if str(submission) in self.DefaultHints: else:
self.DefaultHints[str(submission)] += int(1) temporary_dictionary = str(self.hint_database[str(answer)])
return temporary_dictionary = (ast.literal_eval(temporary_dictionary))
else: temporary_dictionary[str(submission)] += int(data['rating'])
temporary_dictionary = str(self.hint_database[str(answer)]) self.hint_database[str(answer)] = temporary_dictionary
temporary_dictionary = (ast.literal_eval(temporary_dictionary)) return
temporary_dictionary[str(submission)] += int(data['rating'])
self.hint_database[str(answer)] = temporary_dictionary
return
@XBlock.json_handler @XBlock.json_handler
def studiodata(self, data, suffix=''): def studiodata(self, data, suffix=''):
......
...@@ -121,7 +121,7 @@ function CrowdXBlock(runtime, element){ ...@@ -121,7 +121,7 @@ function CrowdXBlock(runtime, element){
indexid = indexid.replace(/\=/g, 'eeqquuaallss'); indexid = indexid.replace(/\=/g, 'eeqquuaallss');
if($("#submit"+valueid).length == 0){ if($("#submit"+valueid).length == 0){
$('.hintansarea').append("<p id=\"submit" + valueid + "\" class=\"hintsarea\"> </p>"); $('.hintansarea').append("<p id=\"submit" + valueid + "\" class=\"hintsarea\"> </p>");
$('#submit'+valueid).append("<p> </p><b>Incorrect Answer: \b" + " " + value + "<p> <input id=\"submitbuttonfor" + indexid + "\" style=\"float: right; float: top;\" type=\"button\" class=\"submitbutton\" value=\"Submit a hint\"> <p id=\"hintstoshow" + valueid + "\"> <b><u>Hints in the Data Base:</u>\b </p></div>"); $('#submit'+valueid).append("<p> </p><b>Incorrect Answer: \b" + " " + value + "<p> <input id=\"submitbuttonfor" + valueid + "\" style=\"float: right; float: top;\" type=\"button\" class=\"submitbutton\" value=\"Submit a hint\"> <p id=\"hintstoshow" + valueid + "\"> <b><u>Hints in the Data Base:</u>\b </p></div>");
} }
if(indexid.slice(0,22) != "There are no hints for"){ if(indexid.slice(0,22) != "There are no hints for"){
if($.inArray(index, HintUsed) == -1){ if($.inArray(index, HintUsed) == -1){
...@@ -148,42 +148,43 @@ function CrowdXBlock(runtime, element){ ...@@ -148,42 +148,43 @@ function CrowdXBlock(runtime, element){
if(issubmitting == repeatcounter){ if(issubmitting == repeatcounter){
id = this.id; id = this.id;
id = id.slice(15); id = id.slice(15);
value = document.getElementById(id).getAttribute('data-value'); //value = document.getElementById(id).getAttribute('data-value');
$('.submitbutton').show(); $('.submitbutton').show();
$('.math').remove(); $('.math').remove();
$('#submit').remove(); $('#submit').remove();
$(this).hide(); $(this).hide();
$('#hintstoshow' + value).prepend("<p><input type=\"text\" name=\"studentinput\" id=\"" + id + "\" class=\"math\" size=\"40\"><input id=\"submit\" type=\"button\" data-is=\"" + id + "\" class=\"button\" value=\"Submit Hint\"> </p>"); $('#hintstoshow' + id).prepend("<p><input type=\"text\" name=\"studentinput\" id=\"" + id + "\" class=\"math\" size=\"40\"><input id=\"submit\" type=\"button\" data-is=\"" + id + "\" class=\"button\" value=\"Submit Hint\"> </p>");
}}) }})
$(document).on('click', '#submit', function(){ $(document).on('click', '#submit', function(){
issubmittinghint += 1; issubmittinghint += 1;
if(issubmittinghint == repeatcounter){ if(issubmittinghint == repeatcounter){
if($('.math').val() != null){ if($('.math').val() != null){
var answerdata = String;
var valueid = String; var valueid = String;
issubmitting = 0; issubmitting = 0;
$('#submit').each(function(){ $('#submit').each(function(){
valueid = $(this).attr('data-is'); answerdata = $('.math').attr('id');
}); });
$('.submitbutton').show(); $('.submitbutton').show();
console.log('valueidworks' + valueid); console.log('valueidworks' + valueid);
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: runtime.handlerUrl(element, 'give_hint'), url: runtime.handlerUrl(element, 'give_hint'),
data: JSON.stringify({"submission": $('.math').val(), "answer": valueid}), //give hin for first incorrect answer data: JSON.stringify({"submission": $('.math').val(), "answer": answerdata}), //give hin for first incorrect answer
success: finish //success: finish
}); });
$("#answer").val(''); $("#answer").val('');
data_value = document.getElementById(valueid).getAttribute('data-value'); //data_value = document.getElementById(valueid).getAttribute('data-value');
data_value = String('hintstoshow' + data_value); data_value = String('hintstoshow' + answerdata);
$(this).remove(); $(this).remove();
$('.math').remove(); $('.math').remove();
document.getElementById("submitbuttonfor" + valueid).remove(); document.getElementById("submitbuttonfor" + answerdata).remove();
$('#submitbuttonfor' + valueid).remove(); $('#submitbuttonfor' + answerdata).remove();
$('#'+valueid).remove(); $('#'+answerdata).remove();
value = document.getElementById(id).getAttribute('data-value'); //value = document.getElementById(id).getAttribute('data-value');
$('#hintstoshow' + value).prepend("<p> Thankyou! </p>"); //$('#hintstoshow' + value).prepend("<p> Thankyou! </p>");
$('#submit'+valueid).prepend('Thankyou for your hint!'); $('#submit'+answerdata).prepend('Thankyou for your hint!');
}}}) }}})
$(document).on('click', '.hintbutton', function(){ //upvote $(document).on('click', '.hintbutton', function(){ //upvote
......
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