コード例 #1
0
ファイル: runtime.py プロジェクト: ffedoroff/XBlock
 def applicable_aside_types(self, block):
     """
     Return the set of applicable aside types for this runtime and block. This method allows the runtime
     to filter the set of asides it wants to support or to provide even block-level or block_type level
     filtering. We may extend this in the future to also take the user or user roles.
     """
     return [aside_type for aside_type, __ in XBlockAside.load_classes()]
コード例 #2
0
ファイル: runtime.py プロジェクト: edx/XBlock
 def applicable_aside_types(self, block):
     """
     Return the set of applicable aside types for this runtime and block. This method allows the runtime
     to filter the set of asides it wants to support or to provide even block-level or block_type level
     filtering. We may extend this in the future to also take the user or user roles.
     """
     return [aside_type for aside_type, __ in XBlockAside.load_classes()]
コード例 #3
0
ファイル: views.py プロジェクト: davidemezzera/xblock-sdk
def package_resource(_request, block_type, resource):
    """
    Wrapper for `pkg_resources` that tries to access a resource and, if it
    is not found, raises an Http404 error.
    """
    try:
        xblock_class = XBlock.load_class(block_type)
    except PluginMissingError:
        try:
            xblock_class = XBlockAside.load_class(block_type)
        except PluginMissingError:
            raise Http404
    try:
        content = xblock_class.open_local_resource(resource)
    except Exception:
        raise Http404
    mimetype, _ = mimetypes.guess_type(resource)
    return HttpResponse(content, content_type=mimetype)
コード例 #4
0
ファイル: runtime.py プロジェクト: timsneath/edx-platform
    def get_asides(self, block):
        """
        Return all of the asides which might be decorating this `block`.

        Arguments:
            block (:class:`.XBlock`): The block to render retrieve asides for.
        """

        config = XBlockAsidesConfig.current()

        if not config.enabled:
            return []

        if block.scope_ids.block_type in config.disabled_blocks.split():
            return []

        return [
            self.get_aside_of_type(block, aside_type)
            for aside_type, __
            in XBlockAside.load_classes()
        ]
コード例 #5
0
ファイル: runtime.py プロジェクト: Jianbinma/XBlock
    def get_asides(self, block):
        """
        Return all of the asides which might be decorating this `block`.

        Arguments:
            block (:class:`.XBlock`): The block to render retrieve asides for.
        """
        # TODO: This function will need to be extended if we want to allow:
        #   a) XBlockAsides to statically indicated which types of blocks they can comment on
        #   b) XBlockRuntimes to limit the selection of asides to a subset of the installed asides
        #   c) Optimize by only loading asides that actually decorate a particular view

        if self.id_generator is None:
            raise Exception("Runtimes must be supplied with an IdGenerator to load XBlockAsides.")

        usage_id = block.scope_ids.usage_id

        asides = []
        for aside_type, aside_cls in XBlockAside.load_classes():
            definition_id = self.id_reader.get_definition_id(usage_id)
            aside_def_id, aside_usage_id = self.id_generator.create_aside(definition_id, usage_id, aside_type)
            scope_ids = ScopeIds(self.user_id, aside_type, aside_def_id, aside_usage_id)
            asides.append(aside_cls(runtime=self, scope_ids=scope_ids))
        return asides
コード例 #6
0
ファイル: runtime.py プロジェクト: Jianbinma/XBlock
 def create_aside(self, block_type, keys):
     """
     The aside version of construct_xblock: take a type and key. Return an instance
     """
     aside_cls = XBlockAside.load_class(block_type)
     return aside_cls(runtime=self, scope_ids=keys)
コード例 #7
0
ファイル: runtime.py プロジェクト: ffedoroff/XBlock
 def create_aside(self, block_type, keys):
     """
     The aside version of construct_xblock: take a type and key. Return an instance
     """
     aside_cls = XBlockAside.load_class(block_type)
     return aside_cls(runtime=self, scope_ids=keys)
コード例 #8
0
ファイル: runtime.py プロジェクト: ffedoroff/XBlock
 def load_aside_type(self, aside_type):
     """
     Returns a subclass of :class:`.XBlockAside` that corresponds to the specified `aside_type`.
     """
     return XBlockAside.load_class(aside_type, select=self.select)
コード例 #9
0
ファイル: models.py プロジェクト: devs1991/test_edx_docmode
 def possible_asides(cls):
     """
     Return a list of all asides that are enabled across all XBlocks.
     """
     return [aside_type for aside_type, __ in XBlockAside.load_classes()]
コード例 #10
0
ファイル: runtime.py プロジェクト: edx/XBlock
 def load_aside_type(self, aside_type):
     """
     Returns a subclass of :class:`.XBlockAside` that corresponds to the specified `aside_type`.
     """
     return XBlockAside.load_class(aside_type, select=self.select)
コード例 #11
0
ファイル: models.py プロジェクト: 10clouds/edx-platform
 def possible_asides(cls):
     """
     Return a list of all asides that are enabled across all XBlocks.
     """
     return [aside_type for aside_type, __ in XBlockAside.load_classes()]