Commit 78bf201b by dragonfi

Add shared header sub-XBlock

parent f340d55a
......@@ -9,3 +9,4 @@ from .message import MentoringMessageBlock
from .table import MentoringTableBlock, MentoringTableColumnBlock, MentoringTableColumnHeaderBlock
from .tip import TipBlock
from .title import TitleBlock
from .header import SharedHeaderBlock
# -*- coding: utf-8 -*-
#
# Copyright (C) 2014 Harvard
#
# Authors:
# Xavier Antoviaque <xavier@antoviaque.org>
#
# 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/>.
#
import logging
from lxml import etree
from xblock.fragment import Fragment
from .light_children import LightChild, Scope, String
log = logging.getLogger(__name__)
class SharedHeaderBlock(LightChild):
"""
A shared header block shown under the title.
"""
content = String(help="HTML content of the header", scope=Scope.content, default="")
@classmethod
def init_block_from_node(cls, block, node, attr):
block.light_children = []
node.tag = 'div'
block.content = unicode(etree.tostring(node))
node.tag = 'shared-header'
return block
def student_view(self, context=None):
return Fragment(u"<script type='text/template' id='{}'>\n{}\n</script>".format(
'light-child-template',
self.content
))
def mentoring_view(self, context=None):
return self.student_view(context)
def mentoring_table_view(self, context=None):
return self.student_view(context)
......@@ -35,6 +35,7 @@ from xblock.fragment import Fragment
from .light_children import XBlockWithLightChildren
from .title import TitleBlock
from .header import SharedHeaderBlock
from .html import HTMLBlock
from .message import MentoringMessageBlock
from .utils import get_scenarios_from_path, load_resource, render_template
......@@ -97,7 +98,7 @@ class MentoringBlock(XBlockWithLightChildren):
@property
def steps(self):
return [child for child in self.get_children_objects() if
not isinstance(child, (HTMLBlock, TitleBlock, MentoringMessageBlock))]
not isinstance(child, (HTMLBlock, TitleBlock, MentoringMessageBlock, SharedHeaderBlock))]
@property
def score(self):
......@@ -115,7 +116,7 @@ class MentoringBlock(XBlockWithLightChildren):
def student_view(self, context):
fragment, named_children = self.get_children_fragment(
context, view_name='mentoring_view',
not_instance_of=(MentoringMessageBlock, TitleBlock)
not_instance_of=(MentoringMessageBlock, TitleBlock, SharedHeaderBlock)
)
fragment.add_content(render_template('templates/html/mentoring.html', {
......@@ -170,6 +171,16 @@ class MentoringBlock(XBlockWithLightChildren):
return None
@property
def header(self):
"""
Return the header child.
"""
for child in self.get_children_objects():
if isinstance(child, SharedHeaderBlock):
return child
return None
@property
def has_missing_dependency(self):
"""
Returns True if the student needs to complete another step before being able to complete
......@@ -265,7 +276,7 @@ class MentoringBlock(XBlockWithLightChildren):
completed = False
current_child = None
children = [child for child in self.get_children_objects() \
if not isinstance(child, TitleBlock)]
if not isinstance(child, (TitleBlock, SharedHeaderBlock))]
for child in children:
if child.name and child.name in submissions:
......
......@@ -3,9 +3,10 @@
You need to complete <a href="{{ missing_dependency_url }}">the previous step</a> before
attempting this step.
</div>
{% if self.title %}
{% if self.title or self.header %}
<div class="title">
<h2 class="main">{{ self.title.content }}</h2>
<div class="header">{{ self.header.content|safe }}</div>
</div>
{% endif %}
{% for name, c in named_children %}
......
<mentoring url_name="{{ url_name }}" display_name="Nav tooltip title" weight="1" mode="assessment">
<title>Default Title</title>
<shared-header>
<p>This paragraph is shared between <strong>all</strong> questions.</p>
</shared-header>
<html>
<p>What is your goal?</p>
</html>
......
......@@ -59,7 +59,8 @@ BLOCKS_CHILDREN = [
'tip = mentoring:TipBlock',
'choice = mentoring:ChoiceBlock',
'html = mentoring:HTMLBlock',
'title = mentoring:TitleBlock'
'title = mentoring:TitleBlock',
'shared-header = mentoring:SharedHeaderBlock',
]
setup(
......
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