implement importing of course info sections as modules in the course
This commit is contained in:
@@ -17,6 +17,8 @@ from xmodule.course_module import CourseDescriptor
|
||||
from xmodule.mako_module import MakoDescriptorSystem
|
||||
from xmodule.x_module import XModuleDescriptor, XMLParsingSystem
|
||||
|
||||
from xmodule.html_module import HtmlDescriptor
|
||||
|
||||
from . import ModuleStoreBase, Location
|
||||
from .exceptions import ItemNotFoundError
|
||||
|
||||
@@ -423,6 +425,25 @@ class XMLModuleStore(ModuleStoreBase):
|
||||
# after we have the course descriptor.
|
||||
XModuleDescriptor.compute_inherited_metadata(course_descriptor)
|
||||
|
||||
# now import all pieces of course_info which is expected to be stored
|
||||
# in <content_dir>/info or <content_dir>/info/<url_name>
|
||||
if url_name:
|
||||
info_path = self.data_dir / course_dir / 'info' / url_name
|
||||
|
||||
if not os.path.exists(info_path):
|
||||
info_path = self.data_dir / course_dir / 'info'
|
||||
|
||||
# we have a fixed number of .html info files that we expect there
|
||||
for info_filename in ['handouts', 'guest_handouts', 'updates', 'guest_updates']:
|
||||
filepath = info_path / info_filename + '.html'
|
||||
if os.path.exists(filepath):
|
||||
with open(filepath) as info_file:
|
||||
html = info_file.read()
|
||||
loc = Location('i4x', course_descriptor.location.org, course_descriptor.location.course, 'course_info', info_filename)
|
||||
html_module = HtmlDescriptor(system, definition={'data' : html}, **{'location' : loc})
|
||||
self.modules[course_id][html_module.location] = html_module
|
||||
|
||||
|
||||
log.debug('========> Done with course import from {0}'.format(course_dir))
|
||||
return course_descriptor
|
||||
|
||||
|
||||
@@ -323,11 +323,15 @@ class XModule(HTMLSnippet):
|
||||
# cdodge: added to support dynamic substitutions of
|
||||
# links for courseware assets (e.g. images). <link> is passed through from lxml.html parser
|
||||
def rewrite_content_links(self, link):
|
||||
# see if we start with our format, e.g. 'xasset:<filename>'
|
||||
loc = Location(self.location)
|
||||
return XModule._rewrite_content_links(loc, link)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def _rewrite_content_links(loc, link):
|
||||
if link.startswith(XASSET_SRCREF_PREFIX):
|
||||
# yes, then parse out the name
|
||||
name = link[len(XASSET_SRCREF_PREFIX):]
|
||||
loc = Location(self.location)
|
||||
# resolve the reference to our internal 'filepath' which
|
||||
content_loc = StaticContent.compute_location(loc.org, loc.course, name)
|
||||
link = StaticContent.get_url_path_from_location(content_loc)
|
||||
@@ -335,7 +339,6 @@ class XModule(HTMLSnippet):
|
||||
return link
|
||||
|
||||
|
||||
|
||||
def policy_key(location):
|
||||
"""
|
||||
Get the key for a location in a policy file. (Since the policy file is
|
||||
|
||||
Reference in New Issue
Block a user