tie in the normal courseware link url rewriting in capa module since that presents HTML via an Ajax callbacks and not via module_render.py

This commit is contained in:
Chris Dodge
2013-08-05 15:24:19 -04:00
parent 2f27f7c43b
commit 9e96b9525b
3 changed files with 23 additions and 2 deletions

View File

@@ -534,8 +534,16 @@ class CapaModule(CapaFields, XModule):
id=self.location.html_id(), ajax_url=self.system.ajax_url
) + html + "</div>"
# now do the substitutions which are filesystem based, e.g. '/static/' prefixes
return self.system.replace_urls(html)
# now do all the substitutions which the LMS module_render normally does, but
# we need to do here explicitly since we can get called for our HTML via AJAX
html = self.system.replace_urls(html)
if self.system.replace_course_urls:
html = self.system.replace_course_urls(html)
if self.system.replace_jump_to_id_urls:
html = self.system.replace_jump_to_id_urls(html)
return html
def handle_ajax(self, dispatch, data):
"""

View File

@@ -902,6 +902,8 @@ class ModuleSystem(Runtime):
s3_interface=None,
cache=None,
can_execute_unsafe_code=None,
replace_course_urls=None,
replace_jump_to_id_urls=None
):
'''
Create a closure around the system environment.
@@ -978,6 +980,8 @@ class ModuleSystem(Runtime):
self.cache = cache or DoNothingCache()
self.can_execute_unsafe_code = can_execute_unsafe_code or (lambda: False)
self.replace_course_urls = replace_course_urls
self.replace_jump_to_id_urls = replace_jump_to_id_urls
def get(self, attr):
''' provide uniform access to attributes (like etree).'''

View File

@@ -349,6 +349,15 @@ def get_module_for_descriptor_internal(user, descriptor, model_data_cache, cours
data_directory=getattr(descriptor, 'data_dir', None),
course_namespace=descriptor.location._replace(category=None, name=None),
),
replace_course_urls=partial(
static_replace.replace_course_urls,
course_id=course_id
),
replace_jump_to_id_urls=partial(
static_replace.replace_jump_to_id_urls,
course_id=course_id,
jump_to_id_base_url=reverse('jump_to_id', kwargs={'course_id': course_id, 'module_id': ''})
),
node_path=settings.NODE_PATH,
xblock_model_data=xblock_model_data,
publish=publish,