diff --git a/common/lib/xmodule/xmodule/modulestore/xml.py b/common/lib/xmodule/xmodule/modulestore/xml.py index 0c0d750882..9fc0ba29ca 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml.py +++ b/common/lib/xmodule/xmodule/modulestore/xml.py @@ -234,10 +234,16 @@ class XMLModuleStore(ModuleStoreBase): system = ImportSystem(self, org, course, course_dir, tracker) - course_descriptor = system.process_xml(etree.tostring(course_data)) policy_path = self.data_dir / course_dir / 'policy.json' - policy = self.load_policy(policy_path, tracker) + # Special case -- need to change the url_name of the course before + # it gets loaded, so its location and other fields are right + if 'course_url_name' in policy: + new_url_name = policy['course_url_name'] + log.info("changing course url_name to {}".format(new_url_name)) + course_data.set('url_name', new_url_name) + + course_descriptor = system.process_xml(etree.tostring(course_data)) XModuleDescriptor.apply_policy(course_descriptor, policy) # NOTE: The descriptors end up loading somewhat bottom up, which diff --git a/common/lib/xmodule/xmodule/x_module.py b/common/lib/xmodule/xmodule/x_module.py index af3f04e366..d68dd61e3d 100644 --- a/common/lib/xmodule/xmodule/x_module.py +++ b/common/lib/xmodule/xmodule/x_module.py @@ -303,6 +303,10 @@ def policy_key(location): Get the key for a location in a policy file. (Since the policy file is specific to a course, it doesn't need the full location url). """ + # Special case--we need to be able to override the url_name on a course, + # so special case where we look for the course descriptor + if location.category == 'course': + return 'course' return '{cat}/{name}'.format(cat=location.category, name=location.name)