本文整理汇总了Python中xmodule.error_module.ErrorDescriptor.from_descriptor方法的典型用法代码示例。如果您正苦于以下问题:Python ErrorDescriptor.from_descriptor方法的具体用法?Python ErrorDescriptor.from_descriptor怎么用?Python ErrorDescriptor.from_descriptor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xmodule.error_module.ErrorDescriptor
的用法示例。
在下文中一共展示了ErrorDescriptor.from_descriptor方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_preview_module
# 需要导入模块: from xmodule.error_module import ErrorDescriptor [as 别名]
# 或者: from xmodule.error_module.ErrorDescriptor import from_descriptor [as 别名]
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
示例2: test_error_module_from_descriptor
# 需要导入模块: from xmodule.error_module import ErrorDescriptor [as 别名]
# 或者: from xmodule.error_module.ErrorDescriptor import from_descriptor [as 别名]
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)
示例3: test_error_module_from_descriptor
# 需要导入模块: from xmodule.error_module import ErrorDescriptor [as 别名]
# 或者: from xmodule.error_module.ErrorDescriptor import from_descriptor [as 别名]
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)
示例4: load_preview_module
# 需要导入模块: from xmodule.error_module import ErrorDescriptor [as 别名]
# 或者: from xmodule.error_module.ErrorDescriptor import from_descriptor [as 别名]
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
示例5: load_preview_module
# 需要导入模块: from xmodule.error_module import ErrorDescriptor [as 别名]
# 或者: from xmodule.error_module.ErrorDescriptor import from_descriptor [as 别名]
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