コード例 #1
0
ファイル: runtime.py プロジェクト: ffedoroff/XBlock
 def get_block_type(self, def_id):
     """Get a block_type by its definition id."""
     try:
         return self._definitions[def_id]
     except KeyError:
         try:
             return def_id.aside_type
         except AttributeError:
             raise NoSuchDefinition(repr(def_id))
コード例 #2
0
    def get_definition_id_from_aside(self, aside_id):
        """
        Extract the definition_id from an aside id.

        Arguments:
            aside_id: An XBlockAside definition_id
        """
        try:
            return self._aside_defs[aside_id][0]
        except KeyError:
            raise NoSuchDefinition(def_id)
コード例 #3
0
    def get_aside_type_from_definition(self, def_id):
        """
        Parse the type of the aside from an XBlockAside definition_id.

        Arguments:
            def_id: An XBlockAside definition_id.
        """
        try:
            return self._aside_defs[def_id][1]
        except KeyError:
            raise NoSuchDefinition(def_id)
コード例 #4
0
def get_olx_hash_for_definition_key(def_key):
    """
    Given a BundleDefinitionLocator, which identifies a specific version of an
    OLX file, return the hash of the OLX file as given by the Blockstore API.
    """
    if def_key.bundle_version:
        # This is referring to an immutable file (BundleVersions are immutable so this can be aggressively cached)
        files_list = get_bundle_version_files_cached(def_key.bundle_uuid, def_key.bundle_version)
    else:
        # This is referring to a draft OLX file which may be recently updated:
        files_list = get_bundle_draft_files_cached(def_key.bundle_uuid, def_key.draft_name)
    for entry in files_list:
        if entry.path == def_key.olx_path:
            return entry.hash_digest
    raise NoSuchDefinition("Could not load OLX file for key {}".format(def_key))
コード例 #5
0
def xml_for_definition(definition_key):
    """
    Method for loading OLX from Blockstore and parsing it to an etree.
    """
    try:
        xml_str = get_bundle_file_data_with_cache(
            bundle_uuid=definition_key.bundle_uuid,
            path=definition_key.olx_path,
            bundle_version=definition_key.bundle_version,
            draft_name=definition_key.draft_name,
        )
    except blockstore_api.BundleFileNotFound:
        raise NoSuchDefinition("OLX file {} not found in bundle {}.".format(  # lint-amnesty, pylint: disable=raise-missing-from
            definition_key.olx_path, definition_key.bundle_uuid,
        ))
    node = etree.fromstring(xml_str)
    return node
コード例 #6
0
ファイル: runtime.py プロジェクト: stvstnfrd/xblock-sdk
 def get_block_type(self, def_id):
     """Get a block_type by its definition id."""
     try:
         return self._definitions[def_id]
     except KeyError as ex:
         raise NoSuchDefinition(repr(def_id)) from ex