diff --git a/cms/djangoapps/contentstore/views/preview.py b/cms/djangoapps/contentstore/views/preview.py index 0bc31f41c0..fa5ba3380c 100644 --- a/cms/djangoapps/contentstore/views/preview.py +++ b/cms/djangoapps/contentstore/views/preview.py @@ -119,6 +119,20 @@ class PreviewModuleSystem(ModuleSystem): # pylint: disable=abstract-method """ return self.wrap_xblock(block, view_name, Fragment(), context) + def layout_asides(self, block, context, frag, view_name, aside_frag_fns): + position_for_asides = '' + result = Fragment() + result.add_frag_resources(frag) + + for aside, aside_fn in aside_frag_fns: + aside_frag = self.wrap_aside(block, aside, view_name, aside_fn(block, context), context) + aside.save() + result.add_frag_resources(aside_frag) + frag.content = frag.content.replace(position_for_asides, position_for_asides + aside_frag.content) + + result.add_content(frag.content) + return result + class StudioPermissionsService(object): """ diff --git a/cms/lib/xblock/tagging.py b/cms/lib/xblock/tagging.py new file mode 100644 index 0000000000..6a4ec348ec --- /dev/null +++ b/cms/lib/xblock/tagging.py @@ -0,0 +1,92 @@ +""" +Example implementation of Structured Tagging based on XBlockAsides +""" + +from xblock.core import XBlockAside +from xblock.fragment import Fragment +from xblock.fields import Scope, Dict +from xmodule.x_module import STUDENT_VIEW +from xmodule.capa_module import CapaModule +from abc import ABCMeta, abstractproperty +from edxmako.shortcuts import render_to_string + + +_ = lambda text: text + + +class AbstractTag(object): + """ + Abstract class for tags + """ + __metaclass__ = ABCMeta + + @abstractproperty + def key(self): + """ + Subclasses must implement key + """ + raise NotImplementedError('Subclasses must implement key') + + @abstractproperty + def name(self): + """ + Subclasses must implement name + """ + raise NotImplementedError('Subclasses must implement name') + + @abstractproperty + def allowed_values(self): + """ + Subclasses must implement allowed_values + """ + raise NotImplementedError('Subclasses must implement allowed_values') + + +class LearningOutcomeTag(AbstractTag): + """ + Particular implementation tags for learning outcomes + """ + @property + def key(self): + """ Identifier for the learning outcome selector """ + return 'learning_outcome_tag' + + @property + def name(self): + """ Label for the learning outcome selector """ + return _('Learning outcomes') + + @property + def allowed_values(self): + """ Allowed values for the learning outcome selector """ + return {'test1': 'Test 1', 'test2': 'Test 2', 'test3': 'Test 3'} + + +class StructuredTagsAside(XBlockAside): + """ + Aside that allows tagging blocks + """ + saved_tags = Dict(help=_("Dictionary with the available tags"), + scope=Scope.content, + default={},) + available_tags = [LearningOutcomeTag()] + + @XBlockAside.aside_for(STUDENT_VIEW) + def student_view_aside(self, block, context): + """ + Display the tag selector with specific categories and allowed values, + depending on the context. + """ + if isinstance(block, CapaModule): + tags = [] + for tag in self.available_tags: + tags.append({ + 'key': tag.key, + 'title': tag.name, + 'values': tag.allowed_values, + 'current_value': self.saved_tags.get(tag.key, None), + }) + return Fragment(render_to_string('structured_tags_block.html', {'tags': tags})) + #return Fragment(u'
Hello world!!!
') + else: + return Fragment(u'') diff --git a/cms/templates/structured_tags_block.html b/cms/templates/structured_tags_block.html new file mode 100644 index 0000000000..d63fb5d86a --- /dev/null +++ b/cms/templates/structured_tags_block.html @@ -0,0 +1,15 @@ +
+ % for tag in tags: + : + +
\ No newline at end of file diff --git a/cms/templates/studio_xblock_wrapper.html b/cms/templates/studio_xblock_wrapper.html index 129f5775b2..f18dfcd1bd 100644 --- a/cms/templates/studio_xblock_wrapper.html +++ b/cms/templates/studio_xblock_wrapper.html @@ -150,7 +150,9 @@ messages = xblock.validate().to_json() % endif % if not is_root: + + % if is_reorderable: % else: diff --git a/common/lib/xmodule/setup.py b/common/lib/xmodule/setup.py index 1bf6ce5324..53c0ce6d04 100644 --- a/common/lib/xmodule/setup.py +++ b/common/lib/xmodule/setup.py @@ -44,6 +44,9 @@ XBLOCKS = [ "vertical = xmodule.vertical_block:VerticalBlock", "wrapper = xmodule.wrapper_module:WrapperBlock", ] +XBLOCKS_ASIDES = [ + 'tagging_aside = cms.lib.xblock.tagging:StructuredTagsAside', +] setup( name="XModule", @@ -66,6 +69,7 @@ setup( entry_points={ 'xblock.v1': XMODULES + XBLOCKS, 'xmodule.v1': XMODULES, + 'xblock_asides.v1': XBLOCKS_ASIDES, 'console_scripts': [ 'xmodule_assets = xmodule.static_content:main', ],