Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
825aaed6
Commit
825aaed6
authored
Mar 31, 2015
by
Syed Hassan Raza
Committed by
Adam Palay
Apr 08, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split course's assests can access through '/' in asset url
parent
08cb8dd5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
1 deletions
+48
-1
cms/djangoapps/contentstore/views/tests/test_assets.py
+40
-0
common/djangoapps/contentserver/middleware.py
+2
-0
common/djangoapps/static_replace/__init__.py
+6
-1
No files found.
cms/djangoapps/contentstore/views/tests/test_assets.py
View file @
825aaed6
...
@@ -14,9 +14,11 @@ from xmodule.assetstore import AssetMetadata
...
@@ -14,9 +14,11 @@ from xmodule.assetstore import AssetMetadata
from
xmodule.contentstore.content
import
StaticContent
from
xmodule.contentstore.content
import
StaticContent
from
xmodule.contentstore.django
import
contentstore
from
xmodule.contentstore.django
import
contentstore
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore
import
ModuleStoreEnum
from
xmodule.modulestore.xml_importer
import
import_course_from_xml
from
xmodule.modulestore.xml_importer
import
import_course_from_xml
from
django.test.utils
import
override_settings
from
django.test.utils
import
override_settings
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
,
AssetLocation
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
,
AssetLocation
from
static_replace
import
replace_static_urls
import
mock
import
mock
from
ddt
import
ddt
from
ddt
import
ddt
from
ddt
import
data
from
ddt
import
data
...
@@ -86,6 +88,44 @@ class BasicAssetsTestCase(AssetsTestCase):
...
@@ -86,6 +88,44 @@ class BasicAssetsTestCase(AssetsTestCase):
# Note: Actual contentType for textbook.pdf in asset.json is 'text/pdf'
# Note: Actual contentType for textbook.pdf in asset.json is 'text/pdf'
self
.
assertEqual
(
content
.
content_type
,
'application/pdf'
)
self
.
assertEqual
(
content
.
content_type
,
'application/pdf'
)
def
test_relative_url_for_split_course
(
self
):
"""
Test relative path for split courses assets
"""
with
modulestore
()
.
default_store
(
ModuleStoreEnum
.
Type
.
split
):
module_store
=
modulestore
()
course_id
=
module_store
.
make_course_key
(
'edX'
,
'toy'
,
'2012_Fall'
)
import_course_from_xml
(
module_store
,
self
.
user
.
id
,
TEST_DATA_DIR
,
[
'toy'
],
static_content_store
=
contentstore
(),
target_id
=
course_id
,
create_if_not_present
=
True
)
course
=
module_store
.
get_course
(
course_id
)
filename
=
'sample_static.txt'
html_src_attribute
=
'"/static/{}"'
.
format
(
filename
)
asset_url
=
replace_static_urls
(
html_src_attribute
,
course_id
=
course
.
id
)
url
=
asset_url
.
replace
(
'"'
,
''
)
base_url
=
url
.
replace
(
filename
,
''
)
self
.
assertTrue
(
"/{}"
.
format
(
filename
)
in
url
)
resp
=
self
.
client
.
get
(
url
)
self
.
assertEquals
(
resp
.
status_code
,
200
)
# simulation of html page where base_url is up-to asset's main directory
# and relative_path is dom element with its src
relative_path
=
'just_a_test.jpg'
# browser append relative_path with base_url
absolute_path
=
base_url
+
relative_path
self
.
assertTrue
(
"/{}"
.
format
(
relative_path
)
in
absolute_path
)
resp
=
self
.
client
.
get
(
absolute_path
)
self
.
assertEquals
(
resp
.
status_code
,
200
)
class
PaginationTestCase
(
AssetsTestCase
):
class
PaginationTestCase
(
AssetsTestCase
):
"""
"""
...
...
common/djangoapps/contentserver/middleware.py
View file @
825aaed6
...
@@ -31,6 +31,8 @@ class StaticContentServer(object):
...
@@ -31,6 +31,8 @@ class StaticContentServer(object):
request
.
path
.
startswith
(
'/'
+
XASSET_LOCATION_TAG
+
'/'
)
or
request
.
path
.
startswith
(
'/'
+
XASSET_LOCATION_TAG
+
'/'
)
or
request
.
path
.
startswith
(
'/'
+
AssetLocator
.
CANONICAL_NAMESPACE
)
request
.
path
.
startswith
(
'/'
+
AssetLocator
.
CANONICAL_NAMESPACE
)
):
):
if
AssetLocator
.
CANONICAL_NAMESPACE
in
request
.
path
:
request
.
path
=
request
.
path
.
replace
(
'block/'
,
'block@'
,
1
)
try
:
try
:
loc
=
StaticContent
.
get_location_from_path
(
request
.
path
)
loc
=
StaticContent
.
get_location_from_path
(
request
.
path
)
except
(
InvalidLocationError
,
InvalidKeyError
):
except
(
InvalidLocationError
,
InvalidKeyError
):
...
...
common/djangoapps/static_replace/__init__.py
View file @
825aaed6
...
@@ -9,6 +9,8 @@ from xmodule.modulestore.django import modulestore
...
@@ -9,6 +9,8 @@ from xmodule.modulestore.django import modulestore
from
xmodule.modulestore
import
ModuleStoreEnum
from
xmodule.modulestore
import
ModuleStoreEnum
from
xmodule.contentstore.content
import
StaticContent
from
xmodule.contentstore.content
import
StaticContent
from
opaque_keys.edx.locator
import
AssetLocator
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
...
@@ -152,7 +154,6 @@ def replace_static_urls(text, data_directory=None, course_id=None, static_asset_
...
@@ -152,7 +154,6 @@ def replace_static_urls(text, data_directory=None, course_id=None, static_asset_
"""
"""
Replace a single matched url.
Replace a single matched url.
"""
"""
# Don't mess with things that end in '?raw'
# Don't mess with things that end in '?raw'
if
rest
.
endswith
(
'?raw'
):
if
rest
.
endswith
(
'?raw'
):
return
original
return
original
...
@@ -180,6 +181,10 @@ def replace_static_urls(text, data_directory=None, course_id=None, static_asset_
...
@@ -180,6 +181,10 @@ def replace_static_urls(text, data_directory=None, course_id=None, static_asset_
# if not, then assume it's courseware specific content and then look in the
# if not, then assume it's courseware specific content and then look in the
# Mongo-backed database
# Mongo-backed database
url
=
StaticContent
.
convert_legacy_static_url_with_course_id
(
rest
,
course_id
)
url
=
StaticContent
.
convert_legacy_static_url_with_course_id
(
rest
,
course_id
)
if
AssetLocator
.
CANONICAL_NAMESPACE
in
url
:
url
=
url
.
replace
(
'block@'
,
'block/'
,
1
)
# Otherwise, look the file up in staticfiles_storage, and append the data directory if needed
# Otherwise, look the file up in staticfiles_storage, and append the data directory if needed
else
:
else
:
course_path
=
"/"
.
join
((
static_asset_path
or
data_directory
,
rest
))
course_path
=
"/"
.
join
((
static_asset_path
or
data_directory
,
rest
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment