Commit 27dcf96e by dragonfi

Add completed flag to only publish the grade once

parent f0215eec
......@@ -10,7 +10,7 @@ import copy
import urllib
from xblock.core import XBlock
from xblock.fields import Scope, String, Dict, Float
from xblock.fields import Scope, String, Dict, Float, Boolean
from xblock.fragment import Fragment
from .utils import render_template, load_resource
......@@ -62,6 +62,12 @@ class DragAndDropBlock(XBlock):
default={}
)
completed = Boolean(
help="The student has completed the problem at least once",
scope=Scope.user_state,
default=False
)
has_score = True
def student_view(self, context):
......@@ -173,15 +179,18 @@ class DragAndDropBlock(XBlock):
if self._is_finished():
final_feedback = self.data['feedback']['finish']
try:
self.runtime.publish(self, 'grade', {
'value': len(self.item_state) / float(tot_items) * self.weight,
'max_value': self.weight,
})
except NotImplementedError:
# Note, this publish method is unimplemented in Studio runtimes,
# so we have to figure that we're running in Studio for now
pass
# only publish the grade once
if not self.completed:
self.completed = True
try:
self.runtime.publish(self, 'grade', {
'value': len(self.item_state) / float(tot_items) * self.weight,
'max_value': self.weight,
})
except NotImplementedError:
# Note, this publish method is unimplemented in Studio runtimes,
# so we have to figure that we're running in Studio for now
pass
self.runtime.publish(self, 'xblock.drag-and-drop-v2.item.dropped', {
'item_id': item['id'],
......
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