Asset urls must start w/ slash
LMS-11233
This commit is contained in:
committed by
Ben McMorran
parent
2839ad8711
commit
78879ebc18
@@ -146,7 +146,7 @@ def get_lms_link_for_about_page(course_key):
|
||||
def course_image_url(course):
|
||||
"""Returns the image url for the course."""
|
||||
loc = StaticContent.compute_location(course.location.course_key, course.course_image)
|
||||
path = loc.to_deprecated_string()
|
||||
path = StaticContent.serialize_asset_key_with_slash(loc)
|
||||
return path
|
||||
|
||||
|
||||
|
||||
@@ -277,7 +277,7 @@ def _get_asset_json(display_name, date, location, thumbnail_location, locked):
|
||||
"""
|
||||
Helper method for formatting the asset information to send to client.
|
||||
"""
|
||||
asset_url = _add_slash(location.to_deprecated_string())
|
||||
asset_url = StaticContent.serialize_asset_key_with_slash(location)
|
||||
external_url = settings.LMS_BASE + asset_url
|
||||
return {
|
||||
'display_name': display_name,
|
||||
@@ -285,14 +285,8 @@ def _get_asset_json(display_name, date, location, thumbnail_location, locked):
|
||||
'url': asset_url,
|
||||
'external_url': external_url,
|
||||
'portable_url': StaticContent.get_static_path_from_location(location),
|
||||
'thumbnail': _add_slash(unicode(thumbnail_location)) if thumbnail_location else None,
|
||||
'thumbnail': StaticContent.serialize_asset_key_with_slash(thumbnail_location) if thumbnail_location else None,
|
||||
'locked': locked,
|
||||
# Needed for Backbone delete/update.
|
||||
'id': unicode(location)
|
||||
}
|
||||
|
||||
|
||||
def _add_slash(url):
|
||||
if not url.startswith('/'):
|
||||
url = '/' + url # TODO - re-address this once LMS-11198 is tackled.
|
||||
return url
|
||||
|
||||
@@ -97,7 +97,7 @@ def replace_static_urls(text, data_directory, course_id=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
|
||||
/static/$course_data_dir/$stuff, or, if course_namespace is not None, by the
|
||||
correct url in the contentstore (c4x://)
|
||||
correct url in the contentstore (/c4x/.. or /asset-loc:..)
|
||||
|
||||
text: The source text to do the substitution in
|
||||
data_directory: The directory in which course data is stored
|
||||
|
||||
@@ -64,9 +64,6 @@ class StaticContent(object):
|
||||
def get_id(self):
|
||||
return self.location
|
||||
|
||||
def get_url_path(self):
|
||||
return self.location.to_deprecated_string()
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
return self._data
|
||||
@@ -108,7 +105,9 @@ class StaticContent(object):
|
||||
assert(isinstance(course_key, CourseKey))
|
||||
placeholder_id = uuid.uuid4().hex
|
||||
# create a dummy asset location with a fake but unique name. strip off the name, and return it
|
||||
url_path = unicode(course_key.make_asset_key('asset', placeholder_id).for_branch(None))
|
||||
url_path = StaticContent.serialize_asset_key_with_slash(
|
||||
course_key.make_asset_key('asset', placeholder_id).for_branch(None)
|
||||
)
|
||||
return url_path.replace(placeholder_id, '')
|
||||
|
||||
@staticmethod
|
||||
@@ -133,7 +132,7 @@ class StaticContent(object):
|
||||
# Generate url of urlparse.path component
|
||||
scheme, netloc, orig_path, params, query, fragment = urlparse(path)
|
||||
loc = StaticContent.compute_location(course_id, orig_path)
|
||||
loc_url = loc.to_deprecated_string()
|
||||
loc_url = StaticContent.serialize_asset_key_with_slash(loc)
|
||||
|
||||
# parse the query params for "^/static/" and replace with the location url
|
||||
orig_query = parse_qsl(query)
|
||||
@@ -144,7 +143,7 @@ class StaticContent(object):
|
||||
course_id,
|
||||
query_value[len('/static/'):],
|
||||
)
|
||||
new_query_url = new_query.to_deprecated_string()
|
||||
new_query_url = StaticContent.serialize_asset_key_with_slash(new_query)
|
||||
new_query_list.append((query_name, new_query_url))
|
||||
else:
|
||||
new_query_list.append((query_name, query_value))
|
||||
@@ -155,6 +154,17 @@ class StaticContent(object):
|
||||
def stream_data(self):
|
||||
yield self._data
|
||||
|
||||
@staticmethod
|
||||
def serialize_asset_key_with_slash(asset_key):
|
||||
"""
|
||||
Legacy code expects the serialized asset key to start w/ a slash; so, do that in one place
|
||||
:param asset_key:
|
||||
"""
|
||||
url = unicode(asset_key)
|
||||
if not url.startswith('/'):
|
||||
url = '/' + url # TODO - re-address this once LMS-11198 is tackled.
|
||||
return url
|
||||
|
||||
|
||||
class StaticContentStream(StaticContent):
|
||||
def __init__(self, loc, name, content_type, stream, last_modified_at=None, thumbnail_location=None, import_path=None,
|
||||
|
||||
@@ -66,7 +66,7 @@ class MongoContentStore(ContentStore):
|
||||
self.delete(content_id) # delete is a noop if the entry doesn't exist; so, don't waste time checking
|
||||
|
||||
thumbnail_location = content.thumbnail_location.to_deprecated_list_repr() if content.thumbnail_location else None
|
||||
with self.fs.new_file(_id=content_id, filename=content.get_url_path(), content_type=content.content_type,
|
||||
with self.fs.new_file(_id=content_id, filename=unicode(content.location), content_type=content.content_type,
|
||||
displayname=content.name, content_son=content_son,
|
||||
thumbnail_location=thumbnail_location,
|
||||
import_path=content.import_path,
|
||||
|
||||
@@ -118,7 +118,7 @@ def course_image_url(course):
|
||||
url += '/images/course_image.jpg'
|
||||
else:
|
||||
loc = StaticContent.compute_location(course.id, course.course_image)
|
||||
url = loc.to_deprecated_string()
|
||||
url = StaticContent.serialize_asset_key_with_slash(loc)
|
||||
return url
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user