Commit 7667b206 by solashirai Committed by Piotr Mitros

code improvement

parent 14587bca
...@@ -102,7 +102,7 @@ class CrowdsourceHinter(XBlock): ...@@ -102,7 +102,7 @@ class CrowdsourceHinter(XBlock):
frag.add_javascript_url('//cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.min.js') frag.add_javascript_url('//cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.min.js')
frag.add_css(self.resource_string("static/css/crowdsourcehinter.css")) frag.add_css(self.resource_string("static/css/crowdsourcehinter.css"))
frag.add_javascript(self.resource_string("static/js/src/crowdsourcehinter.js")) frag.add_javascript(self.resource_string("static/js/src/crowdsourcehinter.js"))
frag.initialize_js('CrowdsourceHinter', {'hinting_element': self.Element, 'isStaff': self.Element}) frag.initialize_js('CrowdsourceHinter', {'hinting_element': self.Element, 'isStaff': self.xmodule_runtime.user_is_staff})
return frag return frag
@XBlock.json_handler @XBlock.json_handler
...@@ -115,7 +115,7 @@ class CrowdsourceHinter(XBlock): ...@@ -115,7 +115,7 @@ class CrowdsourceHinter(XBlock):
data['submittedanswer']: The string of text that the student submits for a problem. data['submittedanswer']: The string of text that the student submits for a problem.
returns: returns:
'HintsToUse': the highest rated hint for an incorrect answer 'Hints': the highest rated hint for an incorrect answer
or another random hint for an incorrect answer or another random hint for an incorrect answer
or 'Sorry, there are no more hints for this answer.' if no more hints exist or 'Sorry, there are no more hints for this answer.' if no more hints exist
""" """
...@@ -146,12 +146,12 @@ class CrowdsourceHinter(XBlock): ...@@ -146,12 +146,12 @@ class CrowdsourceHinter(XBlock):
# currently set by default to True # currently set by default to True
if best_hint not in self.Reported.keys(): if best_hint not in self.Reported.keys():
self.Used.append(best_hint) self.Used.append(best_hint)
return {'HintsToUse': best_hint, "StudentAnswer": answer} return {'Hints': best_hint, "StudentAnswer": answer}
if best_hint not in self.Used: if best_hint not in self.Used:
# choose highest rated hint for the incorrect answer # choose highest rated hint for the incorrect answer
if best_hint not in self.Reported.keys(): if best_hint not in self.Reported.keys():
self.Used.append(best_hint) self.Used.append(best_hint)
return {'HintsToUse': best_hint, "StudentAnswer": answer} return {'Hints': best_hint, "StudentAnswer": answer}
# choose another random hint for the answer. # choose another random hint for the answer.
temporary_hints_list = [] temporary_hints_list = []
for hint_keys in self.hint_database[str(answer)]: for hint_keys in self.hint_database[str(answer)]:
...@@ -160,16 +160,16 @@ class CrowdsourceHinter(XBlock): ...@@ -160,16 +160,16 @@ class CrowdsourceHinter(XBlock):
temporary_hints_list.append(str(hint_keys)) temporary_hints_list.append(str(hint_keys))
not_used = random.choice(temporary_hints_list) not_used = random.choice(temporary_hints_list)
self.Used.append(not_used) self.Used.append(not_used)
return {'HintsToUse': not_used, "StudentAnswer": answer} return {'Hints': not_used, "StudentAnswer": answer}
# find generic hints for the student if no specific hints exist # find generic hints for the student if no specific hints exist
if len(self.generic_hints) != 0: if len(self.generic_hints) != 0:
not_used = random.choice(self.generic_hints) not_used = random.choice(self.generic_hints)
self.Used.append(not_used) self.Used.append(not_used)
return {'HintsToUse': not_used, "StudentAnswer": answer} return {'Hints': not_used, "StudentAnswer": answer}
else: else:
# if there are no more hints left in either the database or defaults # if there are no more hints left in either the database or defaults
self.Used.append(str("There are no hints for" + " " + answer)) self.Used.append(str("There are no hints for" + " " + answer))
return {'HintsToUse': "Sorry, there are no hints for this answer.", "StudentAnswer": answer} return {'Hints': "Sorry, there are no hints for this answer.", "StudentAnswer": answer}
def find_hints(self, answer): def find_hints(self, answer):
""" """
......
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
<div class="crowdsourcehinter_block"> <div class="crowdsourcehinter_block">
<div class='csh_hint_reveal'> <div class='csh_hint_reveal'>
<div class='csh_HintsToUse' student_answer = '' hint_received=''> <div class='csh_Hints' student_answer = '' hint_received=''>
</div> </div>
<div class='csh_HintQuickFeedback'> <div class='csh_HintQuickFeedback'>
<div role="button" class="csh_rate_hint" data-rate="upvote" title="This hint was helpful!"> <div role="button" class="csh_rate_hint" data-rate="upvote" title="This hint was helpful!">
......
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