Commit 47fc6791 by Filippo Valsorda

Introduce grading

parent cf3b5f1c
...@@ -9,7 +9,7 @@ import webob ...@@ -9,7 +9,7 @@ import webob
import copy import copy
from xblock.core import XBlock from xblock.core import XBlock
from xblock.fields import Scope, String, Dict from xblock.fields import Scope, String, Dict, Float
from xblock.fragment import Fragment from xblock.fragment import Fragment
from .utils import render_template from .utils import render_template
...@@ -40,6 +40,13 @@ class DragAndDropBlock(XBlock): ...@@ -40,6 +40,13 @@ class DragAndDropBlock(XBlock):
default="" default=""
) )
weight = Float(
display_name="Weight",
help="This is the maximum score that the user receives when he/she successfully completes the problem",
scope=Scope.settings,
default=1
)
data = Dict( data = Dict(
display_name="Drag and Drop", display_name="Drag and Drop",
help="JSON spec as generated by the builder", help="JSON spec as generated by the builder",
...@@ -61,14 +68,20 @@ class DragAndDropBlock(XBlock): ...@@ -61,14 +68,20 @@ class DragAndDropBlock(XBlock):
default={} default={}
) )
has_score = True
def student_view(self, context): def student_view(self, context):
""" """
Player view, displayed to the student Player view, displayed to the student
""" """
max_score_string = '({0} Point{1} Possible)'.format(int(self.weight),
's' if self.weight > 1 else '') if self.weight else ''
context = { context = {
'title': self.display_name, 'title': self.display_name,
'question_text': self.question_text 'question_text': self.question_text,
'max_score_string': max_score_string
} }
fragment = Fragment() fragment = Fragment()
...@@ -116,6 +129,7 @@ class DragAndDropBlock(XBlock): ...@@ -116,6 +129,7 @@ class DragAndDropBlock(XBlock):
def studio_submit(self, submissions, suffix=''): def studio_submit(self, submissions, suffix=''):
self.display_name = submissions['display_name'] self.display_name = submissions['display_name']
self.question_text = submissions['question_text'] self.question_text = submissions['question_text']
self.weight = float(submissions['weight'])
try: try:
self.data = json.loads(submissions['data']) self.data = json.loads(submissions['data'])
...@@ -159,6 +173,16 @@ class DragAndDropBlock(XBlock): ...@@ -159,6 +173,16 @@ class DragAndDropBlock(XBlock):
else: else:
final_feedback = None final_feedback = None
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
return { return {
'correct': True, 'correct': True,
'final_feedback': final_feedback, 'final_feedback': final_feedback,
......
...@@ -411,6 +411,7 @@ function DragAndDropEditBlock(runtime, element) { ...@@ -411,6 +411,7 @@ function DragAndDropEditBlock(runtime, element) {
var data = { var data = {
'display_name': $(element).find('.display-name').val(), 'display_name': $(element).find('.display-name').val(),
'weight': $(element).find('.weight').val(),
'question_text': $(element).find('.question-text').val(), 'question_text': $(element).find('.question-text').val(),
'data': JSON.stringify(_fn.data), 'data': JSON.stringify(_fn.data),
}; };
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
{{ title }} {{ title }}
</h2> </h2>
<div class="problem-progress">(1 point possible)</div> <div class="problem-progress">{{ max_score_string }}</div>
<section class="problem" role="application"> <section class="problem" role="application">
<p> <p>
......
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
<h3>Question title</h3> <h3>Question title</h3>
<input class="display-name" /> <input class="display-name" />
<h3>Maximum score</h3>
<input class="weight" value="1"/>
<h3>Question text</h3> <h3>Question text</h3>
<textarea class="question-text"></textarea> <textarea class="question-text"></textarea>
......
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