def load_preview_module(request, preview_id, descriptor): """ Return a preview XModule instantiated from the supplied descriptor. request: The active django request preview_id (str): An identifier specifying which preview this module is used for descriptor: An XModuleDescriptor """ system = preview_module_system(request, preview_id, descriptor) try: module = descriptor.xmodule(system) except: log.debug("Unable to load preview module", exc_info=True) module = ErrorDescriptor.from_descriptor(descriptor, error_msg=exc_info_to_str(sys.exc_info())).xmodule(system) # cdodge: Special case if module.location.category == "static_tab": module.get_html = wrap_xmodule(module.get_html, module, "xmodule_tab_display.html") else: module.get_html = wrap_xmodule(module.get_html, module, "xmodule_display.html") # we pass a partially bogus course_id as we don't have the RUN information passed yet # through the CMS. Also the contentstore is also not RUN-aware at this point in time. module.get_html = replace_static_urls( module.get_html, getattr(module, "data_dir", module.location.course), course_id=module.location.org + "/" + module.location.course + "/BOGUS_RUN_REPLACE_WHEN_AVAILABLE", ) module.get_html = save_module(module.get_html, module) return module
def test_error_module_from_descriptor(self): descriptor = MagicMock([XModuleDescriptor], runtime=self.system, location=self.location, _field_data=self.valid_xml) error_descriptor = ErrorDescriptor.from_descriptor( descriptor, self.error_msg) self.assertIsInstance(error_descriptor, ErrorDescriptor) error_descriptor.xmodule_runtime = self.system context_repr = self.system.render(error_descriptor, 'student_view').content self.assertIn(self.error_msg, context_repr) self.assertIn(repr(descriptor), context_repr)
def test_error_module_from_descriptor(self): descriptor = MagicMock( spec=XModuleDescriptor, runtime=self.system, location=self.location, ) error_descriptor = ErrorDescriptor.from_descriptor( descriptor, self.error_msg) self.assertIsInstance(error_descriptor, ErrorDescriptor) error_descriptor.xmodule_runtime = self.system context_repr = self.system.render(error_descriptor, STUDENT_VIEW).content self.assertIn(self.error_msg, context_repr) self.assertIn(repr(descriptor), context_repr)
def load_preview_module(request, preview_id, descriptor): """ Return a preview XModule instantiated from the supplied descriptor. request: The active django request preview_id (str): An identifier specifying which preview this module is used for descriptor: An XModuleDescriptor """ system = preview_module_system(request, preview_id, descriptor) try: module = descriptor.xmodule(system) except: log.debug("Unable to load preview module", exc_info=True) module = ErrorDescriptor.from_descriptor( descriptor, error_msg=exc_info_to_str(sys.exc_info()) ).xmodule(system) # cdodge: Special case if module.location.category == 'static_tab': module.get_html = wrap_xmodule( module.get_html, module, "xmodule_tab_display.html", ) else: module.get_html = wrap_xmodule( module.get_html, module, "xmodule_display.html", ) # we pass a partially bogus course_id as we don't have the RUN information passed yet # through the CMS. Also the contentstore is also not RUN-aware at this point in time. module.get_html = replace_static_urls( module.get_html, getattr(module, 'data_dir', module.location.course), course_id=module.location.org + '/' + module.location.course + '/BOGUS_RUN_REPLACE_WHEN_AVAILABLE' ) module.get_html = save_module( module.get_html, module ) return module
def load_preview_module(request, preview_id, descriptor): """ Return a preview XModule instantiated from the supplied descriptor. request: The active django request preview_id (str): An identifier specifying which preview this module is used for descriptor: An XModuleDescriptor """ system = preview_module_system(request, preview_id, descriptor) try: module = descriptor.xmodule(system) except: log.debug("Unable to load preview module", exc_info=True) module = ErrorDescriptor.from_descriptor( descriptor, error_msg=exc_info_to_str(sys.exc_info())).xmodule(system) return module
def load_preview_module(request, preview_id, descriptor): """ Return a preview XModule instantiated from the supplied descriptor, instance_state, and shared_state request: The active django request preview_id (str): An identifier specifying which preview this module is used for descriptor: An XModuleDescriptor instance_state: An instance state string shared_state: A shared state string """ system = preview_module_system(request, preview_id, descriptor) try: module = descriptor.xmodule(system) except: log.debug("Unable to load preview module", exc_info=True) module = ErrorDescriptor.from_descriptor( descriptor, error_msg=exc_info_to_str(sys.exc_info())).xmodule(system) # cdodge: Special case if module.location.category == 'static_tab': module.get_html = wrap_xmodule( module.get_html, module, "xmodule_tab_display.html", ) else: module.get_html = wrap_xmodule( module.get_html, module, "xmodule_display.html", ) module.get_html = replace_static_urls(module.get_html, getattr(module, 'data_dir', module.location.course), course_namespace=Location([ module.location.tag, module.location.org, module.location.course, None, None ])) return module
def load_preview_module(request, preview_id, descriptor): """ Return a preview XModule instantiated from the supplied descriptor. request: The active django request preview_id (str): An identifier specifying which preview this module is used for descriptor: An XModuleDescriptor """ system = preview_module_system(request, preview_id, descriptor) try: module = descriptor.xmodule(system) except: log.debug("Unable to load preview module", exc_info=True) module = ErrorDescriptor.from_descriptor( descriptor, error_msg=exc_info_to_str(sys.exc_info()) ).xmodule(system) # cdodge: Special case if module.location.category == 'static_tab': module.get_html = wrap_xmodule( module.get_html, module, "xmodule_tab_display.html", ) else: module.get_html = wrap_xmodule( module.get_html, module, "xmodule_display.html", ) module.get_html = replace_static_urls( module.get_html, getattr(module, 'data_dir', module.location.course), course_namespace=Location([module.location.tag, module.location.org, module.location.course, None, None]) ) module.get_html = save_module( module.get_html, module ) return module
def load_preview_module(request, preview_id, descriptor): """ Return a preview XModule instantiated from the supplied descriptor. request: The active django request preview_id (str): An identifier specifying which preview this module is used for descriptor: An XModuleDescriptor """ system = preview_module_system(request, preview_id, descriptor) try: module = descriptor.xmodule(system) except: log.debug("Unable to load preview module", exc_info=True) module = ErrorDescriptor.from_descriptor( descriptor, error_msg=exc_info_to_str(sys.exc_info()) ).xmodule(system) return module