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
5989bf6b
Commit
5989bf6b
authored
Aug 20, 2013
by
Chris Dodge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update the PDF textbook url paths as well as update wiki_slug when importing
parent
e79f8c43
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
2 deletions
+58
-2
cms/djangoapps/contentstore/tests/test_contentstore.py
+18
-1
common/lib/xmodule/xmodule/contentstore/content.py
+10
-0
common/lib/xmodule/xmodule/modulestore/xml_importer.py
+20
-0
common/test/data/toy/policies/2012_Fall.json
+10
-1
No files found.
cms/djangoapps/contentstore/tests/test_contentstore.py
View file @
5989bf6b
...
...
@@ -1475,12 +1475,14 @@ class ContentStoreTest(ModuleStoreTestCase):
'run'
:
target_location
.
name
}
target_course_id
=
'{0}/{1}/{2}'
.
format
(
target_location
.
org
,
target_location
.
course
,
target_location
.
name
)
resp
=
self
.
client
.
post
(
reverse
(
'create_new_course'
),
course_data
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
data
=
parse_json
(
resp
)
self
.
assertEqual
(
data
[
'id'
],
target_location
.
url
())
import_from_xml
(
module_store
,
'common/test/data/'
,
[
'
simple
'
],
target_location_namespace
=
target_location
)
import_from_xml
(
module_store
,
'common/test/data/'
,
[
'
toy
'
],
target_location_namespace
=
target_location
)
modules
=
module_store
.
get_items
(
Location
([
target_location
.
tag
,
target_location
.
org
,
target_location
.
course
,
None
,
None
,
None
]))
...
...
@@ -1489,6 +1491,21 @@ class ContentStoreTest(ModuleStoreTestCase):
# we can't specify an exact number since it'll always be changing
self
.
assertGreater
(
len
(
modules
),
10
)
#
# test various re-namespacing elements
#
# first check PDF textbooks, to make sure the url paths got updated
course_module
=
module_store
.
get_instance
(
target_course_id
,
target_location
)
self
.
assertEquals
(
len
(
course_module
.
pdf_textbooks
),
1
)
self
.
assertEquals
(
len
(
course_module
.
pdf_textbooks
[
0
][
"chapters"
]),
2
)
self
.
assertEquals
(
course_module
.
pdf_textbooks
[
0
][
"chapters"
][
0
][
"url"
],
'/c4x/MITx/999/asset/Chapter1.pdf'
)
self
.
assertEquals
(
course_module
.
pdf_textbooks
[
0
][
"chapters"
][
1
][
"url"
],
'/c4x/MITx/999/asset/Chapter2.pdf'
)
# check that URL slug got updated to new course slug
self
.
assertEquals
(
course_module
.
wiki_slug
,
'999'
)
def
test_import_metadata_with_attempts_empty_string
(
self
):
module_store
=
modulestore
(
'direct'
)
import_from_xml
(
module_store
,
'common/test/data/'
,
[
'simple'
])
...
...
common/lib/xmodule/xmodule/contentstore/content.py
View file @
5989bf6b
...
...
@@ -59,6 +59,16 @@ class StaticContent(object):
return
None
@staticmethod
def
is_c4x_path
(
path_string
):
return
path_string
.
startswith
(
'/{0}/'
.
format
(
XASSET_LOCATION_TAG
))
@staticmethod
def
renamespace_c4x_path
(
path_string
,
target_location
):
location
=
StaticContent
.
get_location_from_path
(
path_string
)
location
=
location
.
replace
(
org
=
target_location
.
org
,
course
=
target_location
.
course
)
return
StaticContent
.
get_url_path_from_location
(
location
)
@staticmethod
def
get_static_path_from_location
(
location
):
"""
This utility static method will take a location identifier and create a 'durable' /static/.. URL representation of it.
...
...
common/lib/xmodule/xmodule/modulestore/xml_importer.py
View file @
5989bf6b
...
...
@@ -329,8 +329,28 @@ def remap_namespace(module, target_location_namespace):
module
.
location
=
module
.
location
.
_replace
(
tag
=
target_location_namespace
.
tag
,
org
=
target_location_namespace
.
org
,
course
=
target_location_namespace
.
course
)
else
:
original_location
=
module
.
location
#
# module is a course module
#
module
.
location
=
module
.
location
.
_replace
(
tag
=
target_location_namespace
.
tag
,
org
=
target_location_namespace
.
org
,
course
=
target_location_namespace
.
course
,
name
=
target_location_namespace
.
name
)
#
# There is more re-namespacing work we have to do when importing course modules
#
# remap pdf_textbook urls
for
entry
in
module
.
pdf_textbooks
:
for
chapter
in
entry
.
get
(
'chapters'
,
[]):
if
StaticContent
.
is_c4x_path
(
chapter
.
get
(
'url'
,
''
)):
chapter
[
'url'
]
=
StaticContent
.
renamespace_c4x_path
(
chapter
[
'url'
],
target_location_namespace
)
# if there is a wiki_slug which is the same as the original location (aka default value),
# then remap that so the wiki doesn't point to the old Wiki.
if
module
.
wiki_slug
==
original_location
.
course
:
module
.
wiki_slug
=
target_location_namespace
.
course
module
.
save
()
# then remap children pointers since they too will be re-namespaced
if
hasattr
(
module
,
'children'
):
...
...
common/test/data/toy/policies/2012_Fall.json
View file @
5989bf6b
...
...
@@ -12,7 +12,16 @@
{
"type"
:
"discussion"
,
"name"
:
"Discussion"
},
{
"type"
:
"wiki"
,
"name"
:
"Wiki"
},
{
"type"
:
"progress"
,
"name"
:
"Progress"
}
]
],
"pdf_textbooks"
:
[
{
"tab_title"
:
"Sample Multi Chapter Textbook"
,
"id"
:
"MyTextbook"
,
"chapters"
:
[
{
"url"
:
"/c4x/edX/toy/asset/Chapter1.pdf"
,
"title"
:
"Chapter 1"
},
{
"url"
:
"/c4x/edX/toy/asset/Chapter2.pdf"
,
"title"
:
"Chapter 2"
}
]
}]
},
"chapter/Overview"
:
{
"display_name"
:
"Overview"
...
...
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