add static_asset_path metadata to course, and honor its use in link rewriting
This commit is contained in:
@@ -90,7 +90,7 @@ def replace_course_urls(text, course_id):
|
||||
return re.sub(_url_replace_regex('/course/'), replace_course_url, text)
|
||||
|
||||
|
||||
def replace_static_urls(text, data_directory, course_namespace=None):
|
||||
def replace_static_urls(text, data_directory, course_namespace=None, static_asset_path=''):
|
||||
"""
|
||||
Replace /static/$stuff urls either with their correct url as generated by collectstatic,
|
||||
(/static/$md5_hashed_stuff) or by the course-specific content static url
|
||||
@@ -100,6 +100,7 @@ def replace_static_urls(text, data_directory, course_namespace=None):
|
||||
text: The source text to do the substitution in
|
||||
data_directory: The directory in which course data is stored
|
||||
course_namespace: The course identifier used to distinguish static content for this course in studio
|
||||
static_asset_path: Path for static assets, which overrides data_directory and course_namespace, if nonempty
|
||||
"""
|
||||
|
||||
def replace_static_url(match):
|
||||
@@ -116,7 +117,7 @@ def replace_static_urls(text, data_directory, course_namespace=None):
|
||||
if settings.DEBUG and finders.find(rest, True):
|
||||
return original
|
||||
# if we're running with a MongoBacked store course_namespace is not None, then use studio style urls
|
||||
elif course_namespace is not None and not isinstance(modulestore(), XMLModuleStore):
|
||||
elif (not static_asset_path) and course_namespace is not None and not isinstance(modulestore(), XMLModuleStore):
|
||||
# first look in the static file pipeline and see if we are trying to reference
|
||||
# a piece of static content which is in the mitx repo (e.g. JS associated with an xmodule)
|
||||
if staticfiles_storage.exists(rest):
|
||||
@@ -127,7 +128,7 @@ def replace_static_urls(text, data_directory, course_namespace=None):
|
||||
url = StaticContent.convert_legacy_static_url(rest, course_namespace)
|
||||
# Otherwise, look the file up in staticfiles_storage, and append the data directory if needed
|
||||
else:
|
||||
course_path = "/".join((data_directory, rest))
|
||||
course_path = "/".join((static_asset_path or data_directory, rest))
|
||||
|
||||
try:
|
||||
if staticfiles_storage.exists(rest):
|
||||
@@ -143,7 +144,7 @@ def replace_static_urls(text, data_directory, course_namespace=None):
|
||||
return "".join([quote, url, quote])
|
||||
|
||||
return re.sub(
|
||||
_url_replace_regex('/static/(?!{data_dir})'.format(data_dir=data_directory)),
|
||||
_url_replace_regex('/static/(?!{data_dir})'.format(data_dir=static_asset_path or data_directory)),
|
||||
replace_static_url,
|
||||
text
|
||||
)
|
||||
|
||||
@@ -76,7 +76,7 @@ def replace_course_urls(get_html, course_id):
|
||||
return _get_html
|
||||
|
||||
|
||||
def replace_static_urls(get_html, data_dir, course_namespace=None):
|
||||
def replace_static_urls(get_html, data_dir, course_namespace=None, static_asset_path=''):
|
||||
"""
|
||||
Updates the supplied module with a new get_html function that wraps
|
||||
the old get_html function and substitutes urls of the form /static/...
|
||||
@@ -85,7 +85,7 @@ def replace_static_urls(get_html, data_dir, course_namespace=None):
|
||||
|
||||
@wraps(get_html)
|
||||
def _get_html():
|
||||
return static_replace.replace_static_urls(get_html(), data_dir, course_namespace)
|
||||
return static_replace.replace_static_urls(get_html(), data_dir, course_namespace, static_asset_path=static_asset_path)
|
||||
return _get_html
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@ INHERITABLE_METADATA = (
|
||||
# intended to be set per-course, but can be overridden in for specific
|
||||
# elements. Can be a float.
|
||||
'days_early_for_beta',
|
||||
'giturl' # for git edit link
|
||||
'giturl', # for git edit link
|
||||
'static_asset_path', # for static assets placed outside xcontent contentstore
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user