Beispiel #1
0
 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()]
Beispiel #2
0
 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()]
Beispiel #3
0
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)
Beispiel #4
0
    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()
        ]
Beispiel #5
0
    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
Beispiel #6
0
 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)
Beispiel #7
0
 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)
Beispiel #8
0
 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)
Beispiel #9
0
 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()]
Beispiel #10
0
 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)
Beispiel #11
0
 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()]