Ejemplo n.º 1
0
        def add_definitions_children(usage_key, def_key):
            """
            Recursively add any children of the given XBlock usage+definition to
            usages_found.
            """
            if not does_block_type_support_children(def_key.block_type):
                return
            try:
                xml_node = xml_for_definition(def_key)
            except:  # pylint:disable=bare-except
                log.exception("Unable to load definition {}".format(def_key))
                return

            for child in xml_node:
                if child.tag != 'xblock-include':
                    continue
                try:
                    parsed_include = parse_xblock_include(child)
                    child_usage = usage_for_child_include(
                        usage_key, def_key, parsed_include)
                    child_def_key = definition_for_include(
                        parsed_include, def_key)
                except BundleFormatException:
                    log.exception(
                        "Unable to parse a child of {}".format(def_key))
                    continue
                usages_found[child_usage] = child_def_key
                add_definitions_children(child_usage, child_def_key)
Ejemplo n.º 2
0
 def add_node_as_child(self, block, node, id_generator=None):
     """
     This runtime API should normally be used via
     runtime.get_block() -> block.parse_xml() -> runtime.add_node_as_child
     """
     parsed_include = parse_xblock_include(node)
     self.add_child_include(block, parsed_include)
Ejemplo n.º 3
0
 def add_node_as_child(self, block, node, id_generator=None):
     """
     This runtime API should normally be used via
     runtime.get_block() -> block.parse_xml() -> runtime.add_node_as_child
     """
     try:
         parsed_include = parse_xblock_include(node)
     except BundleFormatException:
         # We need to log the XBlock ID or this will be hard to debug
         log.error("BundleFormatException when parsing XBlock %s", block.scope_ids.usage_id)
         raise  # Also log details and stack trace
     self.add_child_include(block, parsed_include)
 def add_node_as_child(self, block, node, id_generator=None):
     """
     This runtime API should normally be used via
     runtime.get_block() -> block.parse_xml() -> runtime.add_node_as_child
     """
     parent_usage = block.scope_ids.usage_id
     parent_definition = block.scope_ids.def_id
     learning_context = get_learning_context_impl(parent_usage)
     parsed_include = parse_xblock_include(node)
     usage_key = learning_context.usage_for_child_include(parent_usage, parent_definition, parsed_include)
     block.children.append(usage_key)
     if parent_definition.draft_name:
         # Store the <xblock-include /> data which we'll need later if saving changes to this block
         self.child_includes_of(block).append(parsed_include)