Commit 27dcf96e by dragonfi

Add completed flag to only publish the grade once

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