Commit fb4766e6 by Chris Dodge Committed by cahrens

be sure to first import 'extra' course content from base folder as well as a…

be sure to first import 'extra' course content from base folder as well as a special override folder for the course run
parent f1ed5611
...@@ -444,33 +444,39 @@ class XMLModuleStore(ModuleStoreBase): ...@@ -444,33 +444,39 @@ class XMLModuleStore(ModuleStoreBase):
log.debug('========> Done with course import from {0}'.format(course_dir)) log.debug('========> Done with course import from {0}'.format(course_dir))
return course_descriptor return course_descriptor
def load_extra_content(self, system, course_descriptor, category, base_dir, course_dir, url_name): def load_extra_content(self, system, course_descriptor, category, base_dir, course_dir, url_name):
if url_name:
path = base_dir / url_name
if not os.path.exists(path): self._load_extra_content(system, course_descriptor, category, base_dir, course_dir)
path = base_dir
# then look in a override folder based on the course run
if os.path.isdir(base_dir / url_name):
self._load_extra_content(system, course_descriptor, category, base_dir / url_name, course_dir)
def _load_extra_content(self, system, course_descriptor, category, path, course_dir):
for filepath in glob.glob(path/ '*'): for filepath in glob.glob(path/ '*'):
with open(filepath) as f: if not os.path.isdir(filepath):
try: with open(filepath) as f:
html = f.read().decode('utf-8') try:
# tabs are referenced in policy.json through a 'slug' which is just the filename without the .html suffix html = f.read().decode('utf-8')
slug = os.path.splitext(os.path.basename(filepath))[0] # tabs are referenced in policy.json through a 'slug' which is just the filename without the .html suffix
loc = Location('i4x', course_descriptor.location.org, course_descriptor.location.course, category, slug) slug = os.path.splitext(os.path.basename(filepath))[0]
module = HtmlDescriptor(system, definition={'data' : html}, **{'location' : loc}) loc = Location('i4x', course_descriptor.location.org, course_descriptor.location.course, category, slug)
# VS[compat]: module = HtmlDescriptor(system, definition={'data' : html}, **{'location' : loc})
# Hack because we need to pull in the 'display_name' for static tabs (because we need to edit them) # VS[compat]:
# from the course policy # Hack because we need to pull in the 'display_name' for static tabs (because we need to edit them)
if category == "static_tab": # from the course policy
for tab in course_descriptor.tabs or []: if category == "static_tab":
if tab.get('url_slug') == slug: for tab in course_descriptor.tabs or []:
module.metadata['display_name'] = tab['name'] if tab.get('url_slug') == slug:
module.metadata['data_dir'] = course_dir module.metadata['display_name'] = tab['name']
self.modules[course_descriptor.id][module.location] = module module.metadata['data_dir'] = course_dir
except Exception, e: self.modules[course_descriptor.id][module.location] = module
logging.exception("Failed to load {0}. Skipping... Exception: {1}".format(filepath, str(e))) except Exception, e:
system.error_tracker("ERROR: " + str(e)) logging.exception("Failed to load {0}. Skipping... Exception: {1}".format(filepath, str(e)))
system.error_tracker("ERROR: " + str(e))
def get_instance(self, course_id, location, depth=0): def get_instance(self, course_id, location, depth=0):
""" """
......
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