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
0350d15e
Commit
0350d15e
authored
Feb 04, 2013
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make static_replace fall back to data_directory prefix, if it doesn't find the file anywhere else
parent
90107fa8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
15 deletions
+24
-15
common/djangoapps/static_replace/__init__.py
+7
-6
common/djangoapps/static_replace/test/test_static_replace.py
+17
-9
No files found.
common/djangoapps/static_replace/__init__.py
View file @
0350d15e
...
...
@@ -69,6 +69,7 @@ def replace_static_urls(text, data_directory, course_namespace=None):
def
replace_static_url
(
match
):
original
=
match
.
group
(
0
)
prefix
=
match
.
group
(
'prefix'
)
quote
=
match
.
group
(
'quote'
)
rest
=
match
.
group
(
'rest'
)
...
...
@@ -78,16 +79,16 @@ def replace_static_urls(text, data_directory, course_namespace=None):
# If we're in debug mode, and the file as requested exists, then don't change the links
elif
(
settings
.
DEBUG
and
finders
.
find
(
rest
,
True
)):
return
original
# Otherwise, look the file up in staticfiles_storage
# Otherwise, look the file up in staticfiles_storage
without the data directory
else
:
path
=
data_directory
+
'/'
+
rest
try
:
url
=
staticfiles_storage
.
url
(
path
)
# And if that fails,
return the path unmodified
url
=
staticfiles_storage
.
url
(
rest
)
# And if that fails,
assume that it's course content, and add manually data directory
except
Exception
as
err
:
log
.
warning
(
"staticfiles_storage couldn't find path {0}: {1}"
.
format
(
path
,
str
(
err
)))
return
original
rest
,
str
(
err
)))
url
=
""
.
join
([
prefix
,
data_directory
,
'/'
,
rest
])
return
""
.
join
([
quote
,
url
,
quote
])
return
re
.
sub
(
...
...
common/djangoapps/static_replace/test/test_static_replace.py
View file @
0350d15e
...
...
@@ -3,19 +3,20 @@ from static_replace import replace_static_urls, replace_course_urls
from
mock
import
patch
,
Mock
from
xmodule.modulestore
import
Location
from
xmodule.modulestore.mongo
import
MongoModuleStore
from
xmodule.modulestore.xml
import
XMLModuleStore
DATA_DIRECTORY
=
'data_dir'
COURSE_ID
=
'org/course/run'
NAMESPACE
=
Location
(
'org'
,
'course'
,
'run'
,
None
,
None
)
STATIC_SOURCE
=
'"/static/file.png"'
def
test_multi_replace
():
static_source
=
'"/static/file.png"'
course_source
=
'"/course/file.png"'
assert_equals
(
replace_static_urls
(
static_source
,
DATA_DIRECTORY
),
replace_static_urls
(
replace_static_urls
(
static_source
,
DATA_DIRECTORY
),
DATA_DIRECTORY
)
replace_static_urls
(
STATIC_SOURCE
,
DATA_DIRECTORY
),
replace_static_urls
(
replace_static_urls
(
STATIC_SOURCE
,
DATA_DIRECTORY
),
DATA_DIRECTORY
)
)
assert_equals
(
replace_course_urls
(
course_source
,
COURSE_ID
),
...
...
@@ -29,8 +30,7 @@ def test_debug_no_modify(mock_settings, mock_finders):
mock_settings
.
DEBUG
=
True
mock_finders
.
find
.
return_value
=
True
static_source
=
'"/static/file.png"'
assert_equals
(
static_source
,
replace_static_urls
(
static_source
,
DATA_DIRECTORY
))
assert_equals
(
STATIC_SOURCE
,
replace_static_urls
(
STATIC_SOURCE
,
DATA_DIRECTORY
))
mock_finders
.
find
.
assert_called_once_with
(
'file.png'
,
True
)
...
...
@@ -42,15 +42,23 @@ def test_mongo_filestore(mock_modulestore, mock_static_content):
mock_modulestore
.
return_value
=
Mock
(
MongoModuleStore
)
mock_static_content
.
convert_legacy_static_url
.
return_value
=
"c4x://mock_url"
static_source
=
'"/static/file.png"'
# No namespace => no change to path
assert_equals
(
static_source
,
replace_static_urls
(
static_source
,
DATA_DIRECTORY
))
assert_equals
(
'"/static/data_dir/file.png"'
,
replace_static_urls
(
STATIC_SOURCE
,
DATA_DIRECTORY
))
# Namespace => content url
assert_equals
(
'"'
+
mock_static_content
.
convert_legacy_static_url
.
return_value
+
'"'
,
replace_static_urls
(
static_source
,
DATA_DIRECTORY
,
NAMESPACE
)
replace_static_urls
(
STATIC_SOURCE
,
DATA_DIRECTORY
,
NAMESPACE
)
)
mock_static_content
.
convert_legacy_static_url
.
assert_called_once_with
(
'file.png'
,
NAMESPACE
)
@patch
(
'static_replace.settings'
)
@patch
(
'static_replace.modulestore'
)
@patch
(
'static_replace.staticfiles_storage'
)
def
test_data_dir_fallback
(
mock_storage
,
mock_modulestore
,
mock_settings
):
mock_modulestore
.
return_value
=
Mock
(
XMLModuleStore
)
mock_settings
.
DEBUG
=
False
mock_storage
.
url
.
side_effect
=
Exception
assert_equals
(
'"/static/data_dir/file.png"'
,
replace_static_urls
(
STATIC_SOURCE
,
DATA_DIRECTORY
))
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