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
a5bb971c
Commit
a5bb971c
authored
Aug 12, 2013
by
ichuang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add static_asset_path metadata to course, and honor its use in link rewriting
parent
1b111b1d
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
15 additions
and
10 deletions
+15
-10
common/djangoapps/static_replace/__init__.py
+5
-4
common/djangoapps/xmodule_modifiers.py
+2
-2
common/lib/xmodule/xmodule/modulestore/inheritance.py
+2
-1
lms/djangoapps/courseware/courses.py
+2
-2
lms/djangoapps/courseware/module_render.py
+3
-1
lms/xmodule_namespace.py
+1
-0
No files found.
common/djangoapps/static_replace/__init__.py
View file @
a5bb971c
...
...
@@ -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
)
common/djangoapps/xmodule_modifiers.py
View file @
a5bb971c
...
...
@@ -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
...
...
common/lib/xmodule/xmodule/modulestore/inheritance.py
View file @
a5bb971c
...
...
@@ -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
)
...
...
lms/djangoapps/courseware/courses.py
View file @
a5bb971c
...
...
@@ -82,8 +82,8 @@ def get_opt_course_with_access(user, course_id, action):
def
course_image_url
(
course
):
"""Try to look up the image url for the course. If it's not found,
log an error and return the dead link"""
if
isinstance
(
modulestore
(),
XMLModuleStore
):
return
'/static/'
+
course
.
data_dir
+
"/images/course_image.jpg"
if
course
.
lms
.
static_asset_path
or
isinstance
(
modulestore
(),
XMLModuleStore
):
return
'/static/'
+
(
course
.
lms
.
static_asset_path
or
getattr
(
course
,
'data_dir'
,
''
))
+
"/images/course_image.jpg"
else
:
loc
=
course
.
location
.
_replace
(
tag
=
'c4x'
,
category
=
'asset'
,
name
=
'images_course_image.jpg'
)
path
=
StaticContent
.
get_url_path_from_location
(
loc
)
...
...
lms/djangoapps/courseware/module_render.py
View file @
a5bb971c
...
...
@@ -348,6 +348,7 @@ def get_module_for_descriptor_internal(user, descriptor, model_data_cache, cours
static_replace
.
replace_static_urls
,
data_directory
=
getattr
(
descriptor
,
'data_dir'
,
None
),
course_namespace
=
descriptor
.
location
.
_replace
(
category
=
None
,
name
=
None
),
static_asset_path
=
descriptor
.
lms
.
static_asset_path
,
),
replace_course_urls
=
partial
(
static_replace
.
replace_course_urls
,
...
...
@@ -405,7 +406,8 @@ def get_module_for_descriptor_internal(user, descriptor, model_data_cache, cours
module
.
get_html
=
replace_static_urls
(
_get_html
,
getattr
(
descriptor
,
'data_dir'
,
None
),
course_namespace
=
module
.
location
.
_replace
(
category
=
None
,
name
=
None
)
course_namespace
=
module
.
location
.
_replace
(
category
=
None
,
name
=
None
),
static_asset_path
=
descriptor
.
lms
.
static_asset_path
)
# Allow URLs of the form '/course/' refer to the root of multicourse directory
...
...
lms/xmodule_namespace.py
View file @
a5bb971c
...
...
@@ -56,3 +56,4 @@ class LmsNamespace(Namespace):
default
=
None
,
scope
=
Scope
.
settings
)
static_asset_path
=
String
(
help
=
"Path to use for static assets - overrides Studio c4x://"
,
scope
=
Scope
.
settings
,
default
=
''
)
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