Commit 22b300a9 by dragonfi

Add step mixins to XBlocks that can be steps

parent 6af86c3d
......@@ -30,6 +30,7 @@ from lazy import lazy
from xblock.fragment import Fragment
from .light_children import LightChild, Boolean, Scope, String, Integer, Float
from .step import StepMixin
from .models import Answer
from .utils import render_js_template, serialize_opaque_key
......@@ -41,7 +42,7 @@ log = logging.getLogger(__name__)
# Classes ###########################################################
class AnswerBlock(LightChild):
class AnswerBlock(LightChild, StepMixin):
"""
A field where the student enters an answer
......
......@@ -38,6 +38,7 @@ from .title import TitleBlock
from .header import SharedHeaderBlock
from .html import HTMLBlock
from .message import MentoringMessageBlock
from .step import StepParentMixin
from .utils import get_scenarios_from_path, load_resource, render_template
......@@ -48,7 +49,7 @@ log = logging.getLogger(__name__)
# Classes ###########################################################
class MentoringBlock(XBlockWithLightChildren):
class MentoringBlock(XBlockWithLightChildren, StepParentMixin):
"""
An XBlock providing mentoring capabilities
......@@ -98,11 +99,6 @@ class MentoringBlock(XBlockWithLightChildren):
return self.mode == 'assessment'
@property
def steps(self):
return [child for child in self.get_children_objects() if
not isinstance(child, self.FLOATING_BLOCKS + (HTMLBlock,))]
@property
def score(self):
"""Compute the student score taking into account the light child weight."""
total_child_weight = sum(float(step.weight) for step in self.steps)
......@@ -114,22 +110,7 @@ class MentoringBlock(XBlockWithLightChildren):
return (score, int(round(score * 100)), correct, incorrect)
def _index_steps(self):
"""Add an index to each step that can be used in the step's title."""
steps = self.steps
if len(steps) == 1:
steps[0].index = ""
return
index = 1
for child in steps:
child.index = index
index += 1
def student_view(self, context):
self._index_steps()
fragment, named_children = self.get_children_fragment(
context, view_name='mentoring_view',
not_instance_of=self.FLOATING_BLOCKS,
......
......@@ -28,6 +28,7 @@ import logging
from xblock.fragment import Fragment
from .choice import ChoiceBlock
from .step import StepMixin
from .light_children import LightChild, Scope, String, Float
from .tip import TipBlock
from .utils import render_template, render_js_template
......@@ -40,7 +41,7 @@ log = logging.getLogger(__name__)
# Classes ###########################################################
class QuestionnaireAbstractBlock(LightChild):
class QuestionnaireAbstractBlock(LightChild, StepMixin):
"""
An abstract class used for MCQ/MRQ blocks
......
......@@ -4,6 +4,7 @@ class StepParentMixin(object):
The parent must have a get_children_objects() method.
"""
@property
def steps(self):
return [child for child in self.get_children_objects() if isinstance(child, StepMixin)]
......
<div class="xblock-answer" data-completed="{{ self.completed }}">
<h3 class="question-title">QUESTION {{ self.index }}</h3>
<h3 class="question-title">QUESTION {% if not self.lonely_step %}{{ self.step_number }}{% endif %}</h3>
<p>{{ self.question }}</p>
<textarea
class="answer editable" cols="50" rows="10" name="input"
......
<div class="xblock-answer" data-completed="{{ self.completed }}">
<h3 class="question-title">QUESTION {{ self.index }}</h3>
<h3 class="question-title">QUESTION {% if not self.lonely_step %}{{ self.step_number }}{% endif %}</h3>
<p>{{ self.question }}</p>
<blockquote class="answer read_only">
{{ self.student_input|linebreaksbr }}
......
<fieldset class="choices questionnaire">
<legend class="question">
<h3 class="question-title">QUESTION {{ self.index }}</h3>
<h3 class="question-title">QUESTION {% if not self.lonely_step %}{{ self.step_number }}{% endif %}</h3>
<p>{{ self.question }}</p>
</legend>
<div class="choices-list">
......
<fieldset class="rating questionnaire">
<legend class="question">
<h3 class="question-title">QUESTION {{ self.index }}</h3>
<h3 class="question-title">QUESTION {% if not self.lonely_step %}{{ self.step_number }}{% endif %}</h3>
<p>{{ self.question }}</p>
</legend>
<div class="choices-list">
......
<fieldset class="choices questionnaire" data-hide_results="{{self.hide_results}}">
<legend class="question">
<h3 class="question-title">QUESTION {{ self.index }}</h3>
<h3 class="question-title">QUESTION {% if not self.lonely_step %}{{ self.step_number }}{% endif %}</h3>
<p>{{ self.question }}</p>
</legend>
<div class="choices-list">
......
<mentoring url_name="{{ url_name }}" display_name="Nav tooltip title" weight="1" mode="standard">
<title>Default Title</title>
<html>
<p>Please answer the questions below.</p>
</html>
<mrq name="mrq_1_1" type="choices">
<question>What do you like in this MRQ?</question>
<choice value="elegance">Its elegance</choice>
<choice value="beauty">Its beauty</choice>
<choice value="gracefulness">Its gracefulness</choice>
<choice value="bugs">Its bugs</choice>
<tip require="gracefulness">This MRQ is indeed very graceful</tip>
<tip require="elegance,beauty">This is something everyone has to like about this MRQ</tip>
<tip reject="bugs">Nah, there isn't any!</tip>
<message type="on-submit">Thank you for answering!</message>
</mrq>
<message type="completed">
<html><p>Congratulations!</p></html>
</message>
<message type="incomplete">
<html><p>Still some work to do...</p></html>
</message>
</mentoring>
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