Commit 3bd79f11 by Xavier Antoviaque

Add support for <mentoring-table>/<column> to display summaries

parent 0e167005
from .answer import AnswerBlock
from .quizz import QuizzBlock, QuizzTipBlock
from .table import MentoringTableBlock, MentoringTableColumnBlock
from .mentoring import MentoringBlock
......@@ -63,6 +63,14 @@ class AnswerBlock(XBlock):
fragment.initialize_js('AnswerBlock')
return fragment
def mentoring_table_view(self, context=None):
html = render_template('templates/html/answer_table.html', {
'self': self,
})
fragment = Fragment(html)
fragment.add_css(load_resource('static/css/answer_table.css'))
return fragment
def submit(self, submission):
if not self.read_only:
self.student_input = submission[0]['value'].strip()
......
......@@ -8,7 +8,7 @@ from xblock.core import XBlock
from xblock.fields import Boolean, Scope, String
from xblock.fragment import Fragment
from .utils import load_resource, render_template
from .utils import load_resource, render_template, XBlockWithChildrenFragmentsMixin
# Globals ###########################################################
......@@ -18,18 +18,15 @@ log = logging.getLogger(__name__)
# Classes ###########################################################
class MentoringBlock(XBlock):
class MentoringBlock(XBlock, XBlockWithChildrenFragmentsMixin):
"""
An XBlock providing mentoring capabilities
Each block is composed of a text prompt, an input field for a free answer from the student,
and a set of multiple choice questions. The student submits his text answer, and is then asked
the multiple-choice questions. A set of conditions on the answers provided to the multiple-
choices will determine if the student is a) provided mentoring advices and asked to alter
his answer, or b) is given the ok to continue.
Composed of text, answers input fields, and a set of multiple choice quizzes with advices.
A set of conditions on the provided answers and quizzes choices will determine if the
student is a) provided mentoring advices and asked to alter his answer, or b) is given the
ok to continue.
"""
prompt = String(help="Initial text displayed with the text input", default='Your answer?', scope=Scope.content)
attempted = Boolean(help="Has the student attempted this mentoring step?", default=False, scope=Scope.user_state)
completed = Boolean(help="Has the student completed this mentoring step?", default=False, scope=Scope.user_state)
completed_message = String(help="Message to display upon completion", scope=Scope.content, default="")
......@@ -55,14 +52,7 @@ class MentoringBlock(XBlock):
return block
def student_view(self, context):
"""
Create a fragment used to display the XBlock to a student.
`context` is a dictionary used to configure the display (unused)
Returns a `Fragment` object specifying the HTML, CSS, and JavaScript
to display.
"""
fragment, named_children = self.get_children_fragment(context)
fragment, named_children = self.get_children_fragment(context, view_name='mentoring_view')
fragment.add_content(render_template('templates/html/mentoring.html', {
'self': self,
......@@ -80,16 +70,6 @@ class MentoringBlock(XBlock):
return fragment
def get_children_fragment(self, context):
fragment = Fragment()
named_child_frags = []
for child_id in self.children: # pylint: disable=E1101
child = self.runtime.get_block(child_id)
frag = self.runtime.render_child(child, "mentoring_view", context)
fragment.add_frag_resources(frag)
named_child_frags.append((child.name, frag))
return fragment, named_child_frags
@XBlock.json_handler
def submit(self, submissions, suffix=''):
log.info(u'Received submissions: {}'.format(submissions))
......
# -*- coding: utf-8 -*-
# Imports ###########################################################
import logging
from xblock.core import XBlock
from xblock.fields import Scope, String
from xblock.fragment import Fragment
from .utils import load_resource, render_template, XBlockWithChildrenFragmentsMixin
# Globals ###########################################################
log = logging.getLogger(__name__)
# Classes ###########################################################
class MentoringTableBlock(XBlock, XBlockWithChildrenFragmentsMixin):
"""
Table-type display of information from mentoring blocks
Used to present summary of information entered by the students in mentoring blocks.
Supports different types of formatting through the `type` parameter.
"""
type = String(help="Variant of the table to display", scope=Scope.content, default='')
has_children = True
def student_view(self, context):
fragment, named_children = self.get_children_fragment(context, view_name='mentoring_table_view')
fragment.add_content(render_template('templates/html/mentoring-table.html', {
'self': self,
'named_children': named_children,
}))
fragment.add_css(load_resource('static/css/mentoring-table.css'))
return fragment
@staticmethod
def workbench_scenarios():
"""
Sample scenarios which will be displayed in the workbench
"""
return [
("Mentoring - Table 1, Test", load_resource('templates/xml/900_map.xml')),
]
class MentoringTableColumnBlock(XBlock, XBlockWithChildrenFragmentsMixin):
"""
Individual column of a mentoring table
"""
has_children = True
def student_view(self, context=None): # pylint: disable=W0613
"""Returns default student view."""
return Fragment(u"<p>I can only appear inside mentoring-table blocks.</p>")
def mentoring_table_view(self, context):
fragment, named_children = self.get_children_fragment(context, view_name='mentoring_table_view')
fragment.add_content(render_template('templates/html/mentoring-table-column.html', {
'self': self,
'named_children': named_children,
}))
return fragment
......@@ -8,6 +8,7 @@ import os
import pkg_resources
from django.template import Context, Template
from xblock.fragment import Fragment
# Globals ###########################################################
......@@ -33,3 +34,17 @@ def render_template(template_path, context={}):
template = Template(template_str)
return template.render(Context(context))
# Classes ###########################################################
class XBlockWithChildrenFragmentsMixin(object):
def get_children_fragment(self, context, view_name='student_view'):
fragment = Fragment()
named_child_frags = []
for child_id in self.children: # pylint: disable=E1101
child = self.runtime.get_block(child_id)
frag = self.runtime.render_child(child, view_name, context)
fragment.add_frag_resources(frag)
named_child_frags.append((child.name, frag))
return fragment, named_child_frags
......@@ -2,6 +2,8 @@ from setuptools import setup
BLOCKS = [
'mentoring = mentoring:MentoringBlock',
'mentoring-table = mentoring:MentoringTableBlock',
'column = mentoring:MentoringTableColumnBlock',
'answer = mentoring:AnswerBlock',
'quizz = mentoring:QuizzBlock',
'tip = mentoring:QuizzTipBlock',
......
......@@ -14,7 +14,3 @@ blockquote.answer.read_only:before {
margin-right: 0.25em;
vertical-align: -0.4em;
}
blockquote.answer.read_only p {
display inline;
}
.answer-table {
margin-bottom: 20px;
}
.mentoring-table table {
width: 100%;
border: 1px solid;
border-spacing: 0;
border-collapse: collapse;
}
.mentoring-table td {
width: 25%;
padding: 10px;
vertical-align: top;
border: 1px solid;
}
.mentoring-table h3, .mentoring-table h4 {
margin: 0 0 5px;
}
<div class="answer-table">
{{ self.student_input|linebreaksbr }}
</div>
<td>
{% for name, c in named_children %}
{{c.body_html|safe}}
{% endfor %}
</td>
<div class="mentoring-table {{ self.type }}">
<table>
<tr>
{% for name, c in named_children %}
{{c.body_html|safe}}
{% endfor %}
</tr>
</table>
</div>
<vertical>
<mentoring-table type="immunity-map">
<column>
<html><h4>Pre-goal brainstorm</h4></html>
<answer name="pre-goal-brainstorm2" />
<html><h4>You originally submitted:</h4></html>
<answer name="pre-goal-brainstorm" />
</column>
<column>
<html><h4>Pre-goal feedback</h4></html>
<answer name="pre-goal-feedback" />
</column>
<column>
<html><h4>Improvement goal</h4></html>
<answer name="improvement-goal" />
</column>
<column>
<html><h4>Importance of the goal</h4></html>
<answer name="improvement-goal-importance" />
</column>
</mentoring-table>
</vertical>
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