diff --git a/common/djangoapps/xmodule_modifiers.py b/common/djangoapps/xmodule_modifiers.py
index cda3d013cd..431181bfac 100644
--- a/common/djangoapps/xmodule_modifiers.py
+++ b/common/djangoapps/xmodule_modifiers.py
@@ -59,6 +59,7 @@ def replace_static_urls(get_html, prefix, course_namespace=None):
@wraps(get_html)
def _get_html():
+ logging.debug('in replace_static_urls')
return replace_urls(get_html(), staticfiles_prefix=prefix, course_namespace = course_namespace)
return _get_html
diff --git a/common/lib/xmodule/xmodule/capa_module.py b/common/lib/xmodule/xmodule/capa_module.py
index d75e0ff860..587fc09eed 100644
--- a/common/lib/xmodule/xmodule/capa_module.py
+++ b/common/lib/xmodule/xmodule/capa_module.py
@@ -10,7 +10,6 @@ import sys
from datetime import timedelta
from lxml import etree
-from lxml.html import rewrite_links
from pkg_resources import resource_string
from capa.capa_problem import LoncapaProblem
@@ -342,17 +341,6 @@ class CapaModule(XModule):
html = '
'.format(
id=self.location.html_id(), ajax_url=self.system.ajax_url) + html + "
"
- # cdodge: OK, we have to do two rounds of url reference subsitutions
- # one which uses the 'asset library' that is served by the contentstore and the
- # more global /static/ filesystem based static content.
- # NOTE: rewrite_content_links is defined in XModule
- # This is a bit unfortunate and I'm sure we'll try to considate this into
- # a one step process.
- try:
- html = rewrite_links(html, self.rewrite_content_links)
- except:
- logging.error('error rewriting links in {0}'.format(html))
-
# now do the substitutions which are filesystem based, e.g. '/static/' prefixes
return self.system.replace_urls(html, self.metadata['data_dir'])
diff --git a/common/lib/xmodule/xmodule/html_module.py b/common/lib/xmodule/xmodule/html_module.py
index 00577912c8..f6dddfdd4c 100644
--- a/common/lib/xmodule/xmodule/html_module.py
+++ b/common/lib/xmodule/xmodule/html_module.py
@@ -4,7 +4,6 @@ import logging
import os
import sys
from lxml import etree
-from lxml.html import rewrite_links
from path import path
from .x_module import XModule
@@ -29,14 +28,7 @@ class HtmlModule(XModule):
js_module_name = "HTMLModule"
def get_html(self):
- # cdodge: perform link substitutions for any references to course static content (e.g. images)
- _html = self.html
- try:
- _html = rewrite_links(_html, self.rewrite_content_links)
- except:
- logging.error('error rewriting links on the following HTML content: {0}'.format(_html))
-
- return _html
+ return self.html
def __init__(self, system, location, definition, descriptor,
instance_state=None, shared_state=None, **kwargs):
diff --git a/common/lib/xmodule/xmodule/modulestore/xml_importer.py b/common/lib/xmodule/xmodule/modulestore/xml_importer.py
index 6a7d44489b..3c94e25aa2 100644
--- a/common/lib/xmodule/xmodule/modulestore/xml_importer.py
+++ b/common/lib/xmodule/xmodule/modulestore/xml_importer.py
@@ -30,7 +30,7 @@ def import_static_content(modules, data_dir, static_content_store, target_locati
# now import all static assets
- static_dir = '{0}/static/'.format(course_data_dir)
+ static_dir = '{0}/static/'.format(data_dir / course_data_dir)
for dirname, dirnames, filenames in os.walk(static_dir):
for filename in filenames:
@@ -185,7 +185,7 @@ def import_from_xml(store, data_dir, course_dirs=None,
# it as a StaticContent asset
try:
remap_dict = {}
-
+
# use the rewrite_links as a utility means to enumerate through all links
# in the module data. We use that to load that reference into our asset store
# IMPORTANT: There appears to be a bug in lxml.rewrite_link which makes us not be able to
diff --git a/common/lib/xmodule/xmodule/x_module.py b/common/lib/xmodule/xmodule/x_module.py
index 99468946d7..2174d28112 100644
--- a/common/lib/xmodule/xmodule/x_module.py
+++ b/common/lib/xmodule/xmodule/x_module.py
@@ -320,24 +320,6 @@ class XModule(HTMLSnippet):
get is a dictionary-like object '''
return ""
- # cdodge: added to support dynamic substitutions of
- # links for courseware assets (e.g. images). is passed through from lxml.html parser
- def rewrite_content_links(self, link):
- 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):]
- # 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)
-
- return link
-
def policy_key(location):
"""
diff --git a/lms/djangoapps/courseware/courses.py b/lms/djangoapps/courseware/courses.py
index c4dc6fa77b..4b020f3ead 100644
--- a/lms/djangoapps/courseware/courses.py
+++ b/lms/djangoapps/courseware/courses.py
@@ -2,6 +2,7 @@ from collections import defaultdict
from fs.errors import ResourceNotFoundError
from functools import wraps
import logging
+import inspect
from lxml.html import rewrite_links
@@ -21,11 +22,24 @@ from xmodule.x_module import XModule
from static_replace import replace_urls, try_staticfiles_lookup
from courseware.access import has_access
import branding
-
-
+from courseware.models import StudentModuleCache
log = logging.getLogger(__name__)
+def get_request_for_thread():
+ """Walk up the stack, return the nearest first argument named "request"."""
+ frame = None
+ try:
+ for f in inspect.stack()[1:]:
+ frame = f[0]
+ code = frame.f_code
+ if code.co_varnames[:1] == ("request",):
+ return frame.f_locals["request"]
+ elif code.co_varnames[:2] == ("self", "request",):
+ return frame.f_locals["request"]
+ finally:
+ del frame
+
def get_course_by_id(course_id):
"""
@@ -129,10 +143,23 @@ def get_course_about_section(course, section_key):
'effort', 'end_date', 'prerequisites', 'ocw_links']:
try:
+
+ request = get_request_for_thread()
+
+ student_module_cache = StudentModuleCache.cache_for_descriptor_descendents(
+ course.id, request.user, course, depth=2)
+
loc = course.location._replace(category='about', name=section_key)
+ course_module = get_module(request.user, request, loc, student_module_cache, course.id)
+
+ html = ''
+
+ if course_module is not None:
+ html = course_module.get_html()
+
item = modulestore().get_instance(course.id, loc)
- return item.definition['data']
+ return html
except ItemNotFoundError:
log.warning("Missing about section {key} in course {url}".format(
@@ -161,6 +188,7 @@ def get_course_info_section(request, cache, course, section_key):
- guest_updates
"""
+
loc = Location(course.location.tag, course.location.org, course.location.course, 'course_info', section_key)
course_module = get_module(request.user, request, loc, cache, course.id)
diff --git a/lms/djangoapps/courseware/module_render.py b/lms/djangoapps/courseware/module_render.py
index d9f87d77b6..0e3b3a326c 100644
--- a/lms/djangoapps/courseware/module_render.py
+++ b/lms/djangoapps/courseware/module_render.py
@@ -259,6 +259,8 @@ def _get_module(user, request, location, student_module_cache, course_id, positi
module.metadata['data_dir'] if 'data_dir' in module.metadata else '',
course_namespace = module.location._replace(category=None, name=None))
+ logging.debug('in get_module')
+
# Allow URLs of the form '/course/' refer to the root of multicourse directory
# hierarchy of this course
module.get_html = replace_course_urls(module.get_html, course_id)