Beispiel #1
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 #2
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 #3
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 #4
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 #5
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)