Commit cb899cb7 by Xavier Antoviaque

Merge pull request #11 from FiloSottile/grading

Add grading capabilities to mentoring blocks
parents 544ccade ff373b3a
...@@ -104,6 +104,7 @@ class AnswerBlock(LightChild): ...@@ -104,6 +104,7 @@ class AnswerBlock(LightChild):
return { return {
'student_input': self.student_input, 'student_input': self.student_input,
'completed': self.completed, 'completed': self.completed,
'score': 1 if self.completed else 0,
} }
@property @property
......
...@@ -81,6 +81,7 @@ class MCQBlock(QuestionnaireAbstractBlock): ...@@ -81,6 +81,7 @@ class MCQBlock(QuestionnaireAbstractBlock):
'submission': submission, 'submission': submission,
'completed': completed, 'completed': completed,
'tips': tips, 'tips': tips,
'score': 1 if completed else 0,
} }
log.debug(u'MCQ submission result: %s', result) log.debug(u'MCQ submission result: %s', result)
return result return result
......
...@@ -30,7 +30,7 @@ from lxml import etree ...@@ -30,7 +30,7 @@ from lxml import etree
from StringIO import StringIO from StringIO import StringIO
from xblock.core import XBlock from xblock.core import XBlock
from xblock.fields import Boolean, Scope, String from xblock.fields import Boolean, Scope, String, Float
from xblock.fragment import Fragment from xblock.fragment import Fragment
from .light_children import XBlockWithLightChildren from .light_children import XBlockWithLightChildren
...@@ -68,7 +68,9 @@ class MentoringBlock(XBlockWithLightChildren): ...@@ -68,7 +68,9 @@ class MentoringBlock(XBlockWithLightChildren):
default=False, scope=Scope.content) default=False, scope=Scope.content)
display_submit = Boolean(help="Allow to submit current block?", default=True, scope=Scope.content) display_submit = Boolean(help="Allow to submit current block?", default=True, scope=Scope.content)
xml_content = String(help="XML content", default='', scope=Scope.content) xml_content = String(help="XML content", default='', scope=Scope.content)
weight = Float(help="Defines the maximum total grade of the block.", default=0, scope=Scope.content)
icon_class = 'problem' icon_class = 'problem'
has_score = True
def student_view(self, context): def student_view(self, context):
fragment, named_children = self.get_children_fragment(context, view_name='mentoring_view', fragment, named_children = self.get_children_fragment(context, view_name='mentoring_view',
...@@ -136,6 +138,12 @@ class MentoringBlock(XBlockWithLightChildren): ...@@ -136,6 +138,12 @@ class MentoringBlock(XBlockWithLightChildren):
elif completed and self.next_step == self.url_name: elif completed and self.next_step == self.url_name:
self.next_step = self.followed_by self.next_step = self.followed_by
score = sum(r[1]['score'] for r in submit_results) / float(len(submit_results))
self.runtime.publish(self, 'grade', {
'value': score,
'max_value': 1,
})
self.completed = bool(completed) self.completed = bool(completed)
return { return {
'submitResults': submit_results, 'submitResults': submit_results,
......
...@@ -103,7 +103,8 @@ class MRQBlock(QuestionnaireAbstractBlock): ...@@ -103,7 +103,8 @@ class MRQBlock(QuestionnaireAbstractBlock):
'choices': results, 'choices': results,
'message': self.message, 'message': self.message,
'max_attempts': self.max_attempts, 'max_attempts': self.max_attempts,
'num_attempts': self.num_attempts 'num_attempts': self.num_attempts,
'score': sum(1.0 for r in results if r['completed']) / len(results),
} }
log.debug(u'MRQ submissions result: %s', result) log.debug(u'MRQ submissions result: %s', result)
......
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