Commit bacce3e6 by Calen Pennington

Load module contents from the file specified by the filename attribute

parent 9c715b60
......@@ -24,6 +24,11 @@ class HtmlDescriptor(RawDescriptor):
"""
mako_template = "widgets/html-edit.html"
module_class = HtmlModule
filename_extension = "html"
js = {'coffee': [resource_string(__name__, 'js/module/html.coffee')]}
js_module = 'HTML'
@classmethod
def definition_from_file(cls, file, system):
return {'data': file.read()}
......@@ -56,15 +56,30 @@ class XmlDescriptor(XModuleDescriptor):
Mixin class for standardized parsing of from xml
"""
# Extension to append to filename paths
filename_extension = 'xml'
@classmethod
def definition_from_xml(cls, xml_object, system):
"""
Return the definition to be passed to the newly created descriptor
during from_xml
xml_object: An etree Element
"""
raise NotImplementedError("%s does not implement definition_from_xml" % cls.__name__)
@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):
"""
Creates an instance of this descriptor from the supplied xml_data.
......@@ -93,9 +108,17 @@ class XmlDescriptor(XModuleDescriptor):
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(
system,
LazyLoadingDict(lambda: cls.definition_from_xml(xml_object, system)),
LazyLoadingDict(definition_loader),
location=['i4x',
org,
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