当前位置: 首页>>代码示例>>Python>>正文


Python XBlock.load_class方法代码示例

本文整理汇总了Python中xblock.core.XBlock.load_class方法的典型用法代码示例。如果您正苦于以下问题:Python XBlock.load_class方法的具体用法?Python XBlock.load_class怎么用?Python XBlock.load_class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xblock.core.XBlock的用法示例。


在下文中一共展示了XBlock.load_class方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_ambiguous_plugins

# 需要导入模块: from xblock.core import XBlock [as 别名]
# 或者: from xblock.core.XBlock import load_class [as 别名]
def test_ambiguous_plugins():
    # We can load ok blocks even if there are bad blocks.
    cls = XBlock.load_class("good_block")
    assert_is(cls, UnambiguousBlock)

    # Trying to load bad blocks raises an exception.
    expected_msg = (
        "Ambiguous entry points for bad_block: "
        "xblock.test.test_plugin.AmbiguousBlock1, "
        "xblock.test.test_plugin.AmbiguousBlock2"
    )
    with assert_raises_regexp(AmbiguousPluginError, expected_msg):
        XBlock.load_class("bad_block")

    # We can use our own function as the select function.
    class MyOwnException(Exception):
        """We'll raise this from `boom`."""
        pass

    def boom(identifier, entry_points):
        """A select function to prove user-defined functions are called."""
        assert len(entry_points) == 2
        assert identifier == "bad_block"
        raise MyOwnException("This is boom")

    with assert_raises_regexp(MyOwnException, "This is boom"):
        XBlock.load_class("bad_block", select=boom)
开发者ID:Randomwak,项目名称:XBlock,代码行数:29,代码来源:test_plugin.py

示例2: test_nosuch_plugin

# 需要导入模块: from xblock.core import XBlock [as 别名]
# 或者: from xblock.core.XBlock import load_class [as 别名]
def test_nosuch_plugin():
    # We can provide a default class to return for missing plugins.
    cls = XBlock.load_class("nosuch_block", default=UnambiguousBlock)
    assert_is(cls, UnambiguousBlock)

    # If we don't provide a default class, an exception is raised.
    with assert_raises_regexp(PluginMissingError, "nosuch_block"):
        XBlock.load_class("nosuch_block")
开发者ID:Randomwak,项目名称:XBlock,代码行数:10,代码来源:test_plugin.py

示例3: test_nosuch_plugin

# 需要导入模块: from xblock.core import XBlock [as 别名]
# 或者: from xblock.core.XBlock import load_class [as 别名]
def test_nosuch_plugin():
    # We can provide a default class to return for missing plugins.
    cls = XBlock.load_class("nosuch_block", default=UnambiguousBlock)
    assert cls is UnambiguousBlock

    # If we don't provide a default class, an exception is raised.
    with pytest.raises(PluginMissingError, match="nosuch_block"):
        XBlock.load_class("nosuch_block")
开发者ID:edx,项目名称:XBlock,代码行数:10,代码来源:test_plugin.py

示例4: test_plugin_caching

# 需要导入模块: from xblock.core import XBlock [as 别名]
# 或者: from xblock.core.XBlock import load_class [as 别名]
def test_plugin_caching():
    plugin.PLUGIN_CACHE = {}
    assert_equals(_num_plugins_cached(), 0)

    XBlock.load_class("thumbs")
    assert_equals(_num_plugins_cached(), 1)

    XBlock.load_class("thumbs")
    assert_equals(_num_plugins_cached(), 1)
开发者ID:Randomwak,项目名称:XBlock,代码行数:11,代码来源:test_plugin.py

示例5: test_plugin_caching

# 需要导入模块: from xblock.core import XBlock [as 别名]
# 或者: from xblock.core.XBlock import load_class [as 别名]
def test_plugin_caching():
    plugin.PLUGIN_CACHE = {}
    assert _num_plugins_cached() == 0

    XBlock.load_class("thumbs")
    assert _num_plugins_cached() == 1

    XBlock.load_class("thumbs")
    assert _num_plugins_cached() == 1
开发者ID:edx,项目名称:XBlock,代码行数:11,代码来源:test_plugin.py

示例6: load_from_json

# 需要导入模块: from xblock.core import XBlock [as 别名]
# 或者: from xblock.core.XBlock import load_class [as 别名]
    def load_from_json(json_data, system, default_class=None, parent_xblock=None):
        """
        This method instantiates the correct subclass of XModuleDescriptor based
        on the contents of json_data. It does not persist it and can create one which
        has no usage id.

        parent_xblock is used to compute inherited metadata as well as to append the new xblock.

        json_data:
        - 'location' : must have this field
        - 'category': the xmodule category (required or location must be a Location)
        - 'metadata': a dict of locally set metadata (not inherited)
        - 'children': a list of children's usage_ids w/in this course
        - 'definition':
        - '_id' (optional): the usage_id of this. Will generate one if not given one.
        """
        class_ = XBlock.load_class(
            json_data.get("category", json_data.get("location", {}).get("category")),
            default_class,
            select=settings.XBLOCK_SELECT_FUNCTION,
        )
        usage_id = json_data.get("_id", None)
        if not "_inherited_settings" in json_data and parent_xblock is not None:
            json_data["_inherited_settings"] = parent_xblock.xblock_kvs.inherited_settings.copy()
            json_fields = json_data.get("fields", {})
            for field_name in inheritance.InheritanceMixin.fields:
                if field_name in json_fields:
                    json_data["_inherited_settings"][field_name] = json_fields[field_name]

        new_block = system.xblock_from_json(class_, usage_id, json_data)
        if parent_xblock is not None:
            parent_xblock.children.append(new_block.scope_ids.usage_id)
            # decache pending children field settings
            parent_xblock.save()
        return new_block
开发者ID:jswope00,项目名称:edx-platform-sgu,代码行数:37,代码来源:test_crud.py

示例7: test_all_blocks_excluded_from_completion

# 需要导入模块: from xblock.core import XBlock [as 别名]
# 或者: from xblock.core.XBlock import load_class [as 别名]
 def test_all_blocks_excluded_from_completion(self, blockclass):
     xblock = XBlock.load_class(blockclass)
     self.assertEqual(
         XBlockCompletionMode.get_mode(xblock),
         XBlockCompletionMode.EXCLUDED,
         "Block {!r} did not have completion mode 'excluded'".format(xblock),
     )
开发者ID:open-craft,项目名称:xblock-group-project-v2,代码行数:9,代码来源:test_mixins.py

示例8: setUp

# 需要导入模块: from xblock.core import XBlock [as 别名]
# 或者: from xblock.core.XBlock import load_class [as 别名]
    def setUp(self):
        super(TestCourseDetailSerializer, self).setUp()

        # update the expected_data to include the 'overview' data.
        about_descriptor = XBlock.load_class('about')
        overview_template = about_descriptor.get_template('overview.yaml')
        self.expected_data['overview'] = overview_template.get('data')
开发者ID:edx,项目名称:edx-platform,代码行数:9,代码来源:test_serializers.py

示例9: xblock_type_display_name

# 需要导入模块: from xblock.core import XBlock [as 别名]
# 或者: from xblock.core.XBlock import load_class [as 别名]
def xblock_type_display_name(xblock, default_display_name=None):
    """
    Returns the display name for the specified type of xblock. Note that an instance can be passed in
    for context dependent names, e.g. a vertical beneath a sequential is a Unit.

    :param xblock: An xblock instance or the type of xblock.
    :param default_display_name: The default value to return if no display name can be found.
    :return:
    """

    if hasattr(xblock, 'category'):
        category = xblock.category
        if category == 'vertical' and not is_unit(xblock):
            return _('Vertical')
    else:
        category = xblock
    if category == 'chapter':
        return _('Section')
    elif category == 'sequential':
        return _('Subsection')
    elif category == 'vertical':
        return _('Unit')
    component_class = XBlock.load_class(category, select=settings.XBLOCK_SELECT_FUNCTION)
    if hasattr(component_class, 'display_name') and component_class.display_name.default:
        return _(component_class.display_name.default)    # pylint: disable=translation-of-non-string
    else:
        return default_display_name
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:29,代码来源:helpers.py

示例10: construct_xblock

# 需要导入模块: from xblock.core import XBlock [as 别名]
# 或者: from xblock.core.XBlock import load_class [as 别名]
 def construct_xblock(self, plugin_name, field_data, scope_ids, default_class=None, *args, **kwargs):
     """
     Construct a new xblock of the type identified by plugin_name,
     passing *args and **kwargs into __init__
     """
     block_class = XBlock.load_class(plugin_name, default_class)
     return self.construct_xblock_from_class(cls=block_class, field_data=field_data, scope_ids=scope_ids, *args, **kwargs)
开发者ID:qvin,项目名称:XBlock,代码行数:9,代码来源:runtime.py

示例11: _load_mixed_class

# 需要导入模块: from xblock.core import XBlock [as 别名]
# 或者: from xblock.core.XBlock import load_class [as 别名]
def _load_mixed_class(category):
    """
    Load an XBlock by category name, and apply all defined mixins
    """
    component_class = XBlock.load_class(category, select=settings.XBLOCK_SELECT_FUNCTION)
    mixologist = Mixologist(settings.XBLOCK_MIXINS)
    return mixologist.mix(component_class)
开发者ID:PaoloC68,项目名称:edx-platform,代码行数:9,代码来源:component.py

示例12: create_block_from_xml

# 需要导入模块: from xblock.core import XBlock [as 别名]
# 或者: from xblock.core.XBlock import load_class [as 别名]
def create_block_from_xml(xml_data, system, org=None, course=None, default_class=None):
    """
    Create an XBlock instance from XML data.

    `xml_data' is a string containing valid xml.

    `system` is an XMLParsingSystem.

    `org` and `course` are optional strings that will be used in the generated
    block's url identifiers.

    `default_class` is the class to instantiate of the XML indicates a class
    that can't be loaded.

    Returns the fully instantiated XBlock.

    """
    node = etree.fromstring(xml_data)
    raw_class = XBlock.load_class(node.tag, default_class, select=prefer_xmodules)
    xblock_class = system.mixologist.mix(raw_class)

    # leave next line commented out - useful for low-level debugging
    # log.debug('[create_block_from_xml] tag=%s, class=%s' % (node.tag, xblock_class))

    url_name = node.get('url_name', node.get('slug'))
    location = Location('i4x', org, course, node.tag, url_name)

    scope_ids = ScopeIds(None, location.category, location, location)
    xblock = xblock_class.parse_xml(node, system, scope_ids)
    return xblock
开发者ID:SnowGeekOrg,项目名称:edx-platform,代码行数:32,代码来源:xml.py

示例13: xblock_type_display_name

# 需要导入模块: from xblock.core import XBlock [as 别名]
# 或者: from xblock.core.XBlock import load_class [as 别名]
def xblock_type_display_name(xblock, default_display_name=None):
    """
    Returns the display name for the specified type of xblock. Note that an instance can be passed in
    for context dependent names, e.g. a vertical beneath a sequential is a Unit.

    :param xblock: An xblock instance or the type of xblock.
    :param default_display_name: The default value to return if no display name can be found.
    :return:
    """

    if hasattr(xblock, "category"):
        category = xblock.category
        if category == "vertical" and not is_unit(xblock):
            return _("Vertical")
    else:
        category = xblock
    if category == "chapter":
        return _("Section")
    elif category == "sequential":
        return _("Subsection")
    elif category == "vertical":
        return _("Unit")
    component_class = XBlock.load_class(category, select=settings.XBLOCK_SELECT_FUNCTION)
    if hasattr(component_class, "display_name") and component_class.display_name.default:
        return _(component_class.display_name.default)
    else:
        return default_display_name
开发者ID:AdityaKashyap,项目名称:edx-platform,代码行数:29,代码来源:helpers.py

示例14: _process_node

# 需要导入模块: from xblock.core import XBlock [as 别名]
# 或者: from xblock.core.XBlock import load_class [as 别名]
def _process_node(node, usage_factory):
    """Give the XBlock classes a chance to manipulate the tree."""
    block_cls = XBlock.load_class(node.block_name)
    node = block_cls.preprocess_input(node, usage_factory)
    kids = [_process_node(kid, usage_factory) for kid in node.children]
    if any(old is not new for old, new in zip(node.children, kids)):
        node = usage_factory(node.block_name, kids, node.initial_state, node.def_id)
    node = block_cls.postprocess_input(node, usage_factory)
    return node
开发者ID:qvin,项目名称:XBlock,代码行数:11,代码来源:parse.py

示例15: create_xblock

# 需要导入模块: from xblock.core import XBlock [as 别名]
# 或者: from xblock.core.XBlock import load_class [as 别名]
def create_xblock(usage, student_id=None):
    """Create an XBlock instance.

    This will be invoked to create new instances for every request.

    """
    block_cls = XBlock.load_class(usage.block_name)
    runtime = WorkbenchRuntime(block_cls, student_id, usage)
    model = DbModel(MEMORY_KVS, block_cls, student_id, usage)
    block = block_cls(runtime, model)
    return block
开发者ID:dnsserver,项目名称:XBlock,代码行数:13,代码来源:runtime.py


注:本文中的xblock.core.XBlock.load_class方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。