Files
edx-platform/common/lib/xmodule/xmodule/unit_block.py
Braden MacDonald d3f6ed09d8 Learning Contexts, New XBlock Runtime, Blockstore API Client + Content Libraries
https://github.com/edx/edx-platform/pull/20645

This introduces:
* A new XBlock runtime that can read and write XBlocks that are persisted using
  Blockstore instead of Modulestore. The new runtime is currently isolated so
  that it can be tested without risk to the current courseware/runtime.
* Content Libraries v2, which store XBlocks in Blockstore not modulestore
* An API Client for Blockstore
* "Learning Context" plugin API. A learning context is a more abstract concept
  than a course; it's a collection of XBlocks that serves some learning purpose.
2019-08-30 10:31:15 -07:00

74 lines
2.6 KiB
Python

"""
An XBlock which groups related XBlocks together.
This is like the "vertical" block, but without that block's UI code, JavaScript,
and other legacy features.
"""
from __future__ import absolute_import, division, print_function, unicode_literals
from web_fragments.fragment import Fragment
from xblock.completable import XBlockCompletionMode
from xblock.core import XBlock
from xblock.fields import Scope, String
# Make '_' a no-op so we can scrape strings.
_ = lambda text: text
class UnitBlock(XBlock):
"""
Unit XBlock: An XBlock which groups related XBlocks together.
This is like the "vertical" block in principle, but this version is
explicitly designed to not contain LMS-related logic, like vertical does.
The application which renders XBlocks and/or the runtime should manage
things like bookmarks, completion tracking, etc.
This version also avoids any XModule mixins and has no JavaScript code.
"""
has_children = True
# This is a block containing other blocks, so its completion is defined by
# the completion of its child blocks:
completion_mode = XBlockCompletionMode.AGGREGATOR
# Define a non-existent resources dir because we don't have resources, but
# the default will pull in all files in this folder.
resources_dir = 'assets/unit'
display_name = String(
display_name=_("Display Name"),
help=_("The display name for this component."),
scope=Scope.settings,
default=_("Unit"),
)
def student_view(self, context=None):
"""Provide default student view."""
result = Fragment()
child_frags = self.runtime.render_children(self, context=context)
result.add_resources(child_frags)
result.add_content('<div class="unit-xblock vertical">')
for frag in child_frags:
result.add_content(frag.content)
result.add_content('</div>')
return result
def index_dictionary(self):
"""
Return dictionary prepared with module content and type for indexing, so
that the contents of this block can be found in free-text searches.
"""
# return key/value fields in a Python dict object
# values may be numeric / string or dict
xblock_body = super(UnitBlock, self).index_dictionary()
index_body = {
"display_name": self.display_name,
}
if "content" in xblock_body:
xblock_body["content"].update(index_body)
else:
xblock_body["content"] = index_body
# We use "Sequence" for sequentials and units/verticals
xblock_body["content_type"] = "Sequence"
return xblock_body