Commit 54dd9e5e by Calen Pennington

Load module contents from the file specified by the filename attribute

parent aa3e4691
...@@ -24,6 +24,11 @@ class HtmlDescriptor(RawDescriptor): ...@@ -24,6 +24,11 @@ class HtmlDescriptor(RawDescriptor):
""" """
mako_template = "widgets/html-edit.html" mako_template = "widgets/html-edit.html"
module_class = HtmlModule module_class = HtmlModule
filename_extension = "html"
js = {'coffee': [resource_string(__name__, 'js/module/html.coffee')]} js = {'coffee': [resource_string(__name__, 'js/module/html.coffee')]}
js_module = 'HTML' js_module = 'HTML'
@classmethod
def definition_from_file(cls, file, system):
return {'data': file.read()}
...@@ -56,15 +56,30 @@ class XmlDescriptor(XModuleDescriptor): ...@@ -56,15 +56,30 @@ class XmlDescriptor(XModuleDescriptor):
Mixin class for standardized parsing of from xml Mixin class for standardized parsing of from xml
""" """
# Extension to append to filename paths
filename_extension = 'xml'
@classmethod @classmethod
def definition_from_xml(cls, xml_object, system): def definition_from_xml(cls, xml_object, system):
""" """
Return the definition to be passed to the newly created descriptor Return the definition to be passed to the newly created descriptor
during from_xml during from_xml
xml_object: An etree Element
""" """
raise NotImplementedError("%s does not implement definition_from_xml" % cls.__name__) raise NotImplementedError("%s does not implement definition_from_xml" % cls.__name__)
@classmethod @classmethod
def definition_from_file(cls, file, system):
"""
Return the definition to be passed to the newly created descriptor
during from_xml
file: File pointer
"""
return cls.definition_from_xml(etree.parse(file), system)
@classmethod
def from_xml(cls, xml_data, system, org=None, course=None): def from_xml(cls, xml_data, system, org=None, course=None):
""" """
Creates an instance of this descriptor from the supplied xml_data. Creates an instance of this descriptor from the supplied xml_data.
...@@ -93,9 +108,17 @@ class XmlDescriptor(XModuleDescriptor): ...@@ -93,9 +108,17 @@ class XmlDescriptor(XModuleDescriptor):
return metadata return metadata
def definition_loader():
filename = xml_object.get('filename')
if filename is None:
return cls.definition_from_xml(xml_object, system)
else:
filepath = '{type}/{name}.{ext}'.format(type=xml_object.tag, name=filename, ext=cls.filename_extension)
return cls.definition_from_file(system.resources_fs.open(filepath), system)
return cls( return cls(
system, system,
LazyLoadingDict(lambda: cls.definition_from_xml(xml_object, system)), LazyLoadingDict(definition_loader),
location=['i4x', location=['i4x',
org, org,
course, course,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment