Commit 47fc6791 by Filippo Valsorda

Introduce grading

parent cf3b5f1c
......@@ -9,7 +9,7 @@ import webob
import copy
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 .utils import render_template
......@@ -40,6 +40,13 @@ class DragAndDropBlock(XBlock):
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(
display_name="Drag and Drop",
help="JSON spec as generated by the builder",
......@@ -61,14 +68,20 @@ class DragAndDropBlock(XBlock):
default={}
)
has_score = True
def student_view(self, context):
"""
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 = {
'title': self.display_name,
'question_text': self.question_text
'question_text': self.question_text,
'max_score_string': max_score_string
}
fragment = Fragment()
......@@ -116,6 +129,7 @@ class DragAndDropBlock(XBlock):
def studio_submit(self, submissions, suffix=''):
self.display_name = submissions['display_name']
self.question_text = submissions['question_text']
self.weight = float(submissions['weight'])
try:
self.data = json.loads(submissions['data'])
......@@ -159,6 +173,16 @@ class DragAndDropBlock(XBlock):
else:
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 {
'correct': True,
'final_feedback': final_feedback,
......
......@@ -411,6 +411,7 @@ function DragAndDropEditBlock(runtime, element) {
var data = {
'display_name': $(element).find('.display-name').val(),
'weight': $(element).find('.weight').val(),
'question_text': $(element).find('.question-text').val(),
'data': JSON.stringify(_fn.data),
};
......
......@@ -3,7 +3,7 @@
{{ title }}
</h2>
<div class="problem-progress">(1 point possible)</div>
<div class="problem-progress">{{ max_score_string }}</div>
<section class="problem" role="application">
<p>
......
......@@ -9,6 +9,9 @@
<h3>Question title</h3>
<input class="display-name" />
<h3>Maximum score</h3>
<input class="weight" value="1"/>
<h3>Question text</h3>
<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