Commit 7a3423dc by Braden MacDonald

Very basic proof of concept using submissions API

parent dfb4cea9
from .mentoring import MentoringBlock from .mentoring import MentoringBlock
from .answer import AnswerBlock, AnswerRecapBlock from .answer import AnswerBlock, AnswerRecapBlock
from .choice import ChoiceBlock from .choice import ChoiceBlock
from .dashboard import DashboardBlock
from .mcq import MCQBlock, RatingBlock from .mcq import MCQBlock, RatingBlock
from .mrq import MRQBlock from .mrq import MRQBlock
from .message import MentoringMessageBlock from .message import MentoringMessageBlock
......
...@@ -44,7 +44,7 @@ class ChoiceBlock(StudioEditableXBlockMixin, XBlock): ...@@ -44,7 +44,7 @@ class ChoiceBlock(StudioEditableXBlockMixin, XBlock):
""" """
value = String( value = String(
display_name=_("Value"), display_name=_("Value"),
help=_("Value of the choice when selected. Should be unique."), help=_("Value of the choice when selected. Should be unique. Generally you do not need to edit this."),
scope=Scope.content, scope=Scope.content,
default="", default="",
) )
...@@ -54,7 +54,7 @@ class ChoiceBlock(StudioEditableXBlockMixin, XBlock): ...@@ -54,7 +54,7 @@ class ChoiceBlock(StudioEditableXBlockMixin, XBlock):
scope=Scope.content, scope=Scope.content,
default="", default="",
) )
editable_fields = ('content', ) editable_fields = ('content', 'value')
def _(self, text): def _(self, text):
""" translate text """ """ translate text """
......
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014-2015 Harvard, edX & OpenCraft
#
# This software's license gives you freedom; you can copy, convey,
# propagate, redistribute and/or modify this program under the terms of
# the GNU Affero General Public License (AGPL) as published by the Free
# Software Foundation (FSF), either version 3 of the License, or (at your
# option) any later version of the AGPL published by the FSF.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3". If not, see <http://www.gnu.org/licenses/>.
#
# Imports ###########################################################
import logging
from lazy import lazy
from .sub_api import sub_api
from xblock.core import XBlock
from xblock.fields import Scope, String
from xblock.fragment import Fragment
from xblock.validation import ValidationMessage
from xblockutils.studio_editable import StudioEditableXBlockMixin
# Globals ###########################################################
log = logging.getLogger(__name__)
# Make '_' a no-op so we can scrape strings
def _(text):
return text
# Classes ###########################################################
@XBlock.needs("i18n")
class DashboardBlock(StudioEditableXBlockMixin, XBlock):
"""
A block to summarize self-assessment results.
"""
display_name = String(
display_name=_("Display Name"),
help=_("Display name for this module"),
scope=Scope.settings,
default=_('Self-Assessment Summary'),
)
mcq_id = String(
display_name=_("MCQ ID"),
help=_("THe url_name of an MCQ to use as a proof of concept for using the submissions API"),
scope=Scope.content,
default=""
)
editable_fields = ('display_name', 'mcq_id', )
def fallback_view(self, view_name, context=None):
context = context or {}
context['self'] = self
if self.mcq_id:
item_usage_key = self.scope_ids.usage_id.course_key.make_usage_key('pb-mcq', self.mcq_id)
item_key = dict(
student_id=self.runtime.anonymous_student_id,
course_id=unicode(item_usage_key.course_key),
item_id=unicode(item_usage_key),
item_type=item_usage_key.block_type,
)
try:
submission = sub_api.get_submissions(item_key, limit=1)[0]
except (sub_api.SubmissionNotFoundError, IndexError):
message = "(No answer submitted yet)"
else:
message = "Answer is: {}.".format(submission["answer"])
else:
message = "(Not configured)"
fragment = Fragment(u"<h1>Dashboard</h1><p>{}</p>".format(message))
return fragment
...@@ -28,6 +28,7 @@ from xblock.validation import ValidationMessage ...@@ -28,6 +28,7 @@ from xblock.validation import ValidationMessage
from xblockutils.resources import ResourceLoader from xblockutils.resources import ResourceLoader
from .questionnaire import QuestionnaireAbstractBlock from .questionnaire import QuestionnaireAbstractBlock
from .sub_api import sub_api, SubmittingXBlockMixin
# Globals ########################################################### # Globals ###########################################################
...@@ -43,7 +44,7 @@ def _(text): ...@@ -43,7 +44,7 @@ def _(text):
# Classes ########################################################### # Classes ###########################################################
class MCQBlock(QuestionnaireAbstractBlock): class MCQBlock(SubmittingXBlockMixin, QuestionnaireAbstractBlock):
""" """
An XBlock used to ask multiple-choice questions An XBlock used to ask multiple-choice questions
""" """
...@@ -88,6 +89,11 @@ class MCQBlock(QuestionnaireAbstractBlock): ...@@ -88,6 +89,11 @@ class MCQBlock(QuestionnaireAbstractBlock):
}) })
self.student_choice = submission self.student_choice = submission
if sub_api:
# Also send to the submissions API:
sub_api.create_submission(self.student_item_key, submission)
result = { result = {
'submission': submission, 'submission': submission,
'status': 'correct' if correct else 'incorrect', 'status': 'correct' if correct else 'incorrect',
......
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014-2015 Harvard, edX & OpenCraft
#
# This software's license gives you freedom; you can copy, convey,
# propagate, redistribute and/or modify this program under the terms of
# the GNU Affero General Public License (AGPL) as published by the Free
# Software Foundation (FSF), either version 3 of the License, or (at your
# option) any later version of the AGPL published by the FSF.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3". If not, see <http://www.gnu.org/licenses/>.
#
"""
Integrations between these XBlocks and the edX Submissions API
"""
try:
from submissions import api as sub_api
except ImportError:
sub_api = None # We are probably in the workbench. Don't use the submissions API
class SubmittingXBlockMixin(object):
""" Simplifies use of the submissions API by an XBlock """
@property
def student_item_key(self):
""" Get the student_item_dict required for the submissions API """
assert sub_api is not None
location = self.location.replace(branch=None, version=None) # Standardize the key in case it isn't already
return dict(
student_id=self.runtime.anonymous_student_id,
course_id=unicode(location.course_key),
item_id=unicode(location),
item_type=self.scope_ids.block_type,
)
...@@ -53,6 +53,8 @@ BLOCKS = [ ...@@ -53,6 +53,8 @@ BLOCKS = [
'pb-message = mentoring:MentoringMessageBlock', 'pb-message = mentoring:MentoringMessageBlock',
'pb-tip = mentoring:TipBlock', 'pb-tip = mentoring:TipBlock',
'pb-choice = mentoring:ChoiceBlock', 'pb-choice = mentoring:ChoiceBlock',
'pb-dashboard = mentoring:DashboardBlock',
# Deprecated. You can temporarily uncomment and run 'python setup.py develop' if you have these blocks # Deprecated. You can temporarily uncomment and run 'python setup.py develop' if you have these blocks
# installed from testing mentoring v2 and need to get past an error message. # installed from testing mentoring v2 and need to get past an error message.
#'answer = mentoring:AnswerBlock', #'answer = mentoring:AnswerBlock',
......
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