Commit d5d88a6a by Sola Committed by Piotr Mitros

added "Voted" to prevent multiple votes

parent 6d2b720e
...@@ -18,6 +18,7 @@ class CrowdXBlock(XBlock): ...@@ -18,6 +18,7 @@ class CrowdXBlock(XBlock):
WrongAnswers = List(default=[], scope=Scope.user_state) #List of mistakes made by user WrongAnswers = List(default=[], scope=Scope.user_state) #List of mistakes made by user
DefaultHints = Dict(default={"hint": 100, "hinttwo": 10, "hintthree": 0, "hintasdf": 50, "aas;dklfj?": 1000, "SuperDuperBestHint": 10000}, scope=Scope.content) #Default hints in case no incorrect answers in hints match the user's mistake DefaultHints = Dict(default={"hint": 100, "hinttwo": 10, "hintthree": 0, "hintasdf": 50, "aas;dklfj?": 1000, "SuperDuperBestHint": 10000}, scope=Scope.content) #Default hints in case no incorrect answers in hints match the user's mistake
Used = List(default=[], scope=Scope.user_state)#List of used hints from HintsToUse Used = List(default=[], scope=Scope.user_state)#List of used hints from HintsToUse
Voted = Integer(default=0, scope=Scope.user_state)
def student_view(self, context=None): def student_view(self, context=None):
html = self.resource_string("static/html/crowdxblock.html") html = self.resource_string("static/html/crowdxblock.html")
...@@ -77,6 +78,7 @@ class CrowdXBlock(XBlock): ...@@ -77,6 +78,7 @@ class CrowdXBlock(XBlock):
@XBlock.json_handler #add 1 or -1 to rating of a hint @XBlock.json_handler #add 1 or -1 to rating of a hint
def rate_hint(self, data, suffix=''): def rate_hint(self, data, suffix=''):
if self.Voted == 0:
for key in self.hints: for key in self.hints:
tempdict = str(self.hints[str(key)[0]]) #rate hint that is in hints tempdict = str(self.hints[str(key)[0]]) #rate hint that is in hints
tempdict = (ast.literal_eval(tempdict)) tempdict = (ast.literal_eval(tempdict))
...@@ -86,12 +88,15 @@ class CrowdXBlock(XBlock): ...@@ -86,12 +88,15 @@ class CrowdXBlock(XBlock):
print("TESTING AGAIN HI") print("TESTING AGAIN HI")
print("hints are " + str(self.hints[str(key)])) print("hints are " + str(self.hints[str(key)]))
print("otherstuff " + str(self.hints)) print("otherstuff " + str(self.hints))
self.Voted = 1
for key in self.DefaultHints: for key in self.DefaultHints:
if key == self.Used[int(data['ansnum'])]: #rating for hints in DefaultHints if key == self.Used[int(data['ansnum'])]: #rating for hints in DefaultHints
self.DefaultHints[str(key)] += int(data["rating"]) self.DefaultHints[str(key)] += int(data["rating"])
self.Voted = 1
@XBlock.json_handler @XBlock.json_handler
def give_hint(self, data, suffix=''): #add student-made hint into hints def give_hint(self, data, suffix=''): #add student-made hint into hints
if self.Voted == 0:
for key in self.hints: for key in self.hints:
if str(key) == str(self.WrongAnswers[0]): if str(key) == str(self.WrongAnswers[0]):
if str(data['submission']) not in self.hints[str(key)]: if str(data['submission']) not in self.hints[str(key)]:
...@@ -99,8 +104,10 @@ class CrowdXBlock(XBlock): ...@@ -99,8 +104,10 @@ class CrowdXBlock(XBlock):
tempdict = (ast.literal_eval(tempdict)) tempdict = (ast.literal_eval(tempdict))
tempdict.update({data['submission']: 0}) tempdict.update({data['submission']: 0})
self.hints[str(key)] = tempdict self.hints[str(key)] = tempdict
self.Voted = 1
else: else:
self.hints[str(key)[str(data['submission'])]] += 1 self.hints[str(key)[str(data['submission'])]] += 1
self.Voted = 1
@staticmethod @staticmethod
def workbench_scenarios(): def workbench_scenarios():
......
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