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)
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)
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)
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)
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)