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
1789814c
Commit
1789814c
authored
Apr 02, 2013
by
Chris Dodge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
63085ec6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
40 deletions
+50
-40
cms/djangoapps/contentstore/views.py
+2
-1
common/lib/xmodule/xmodule/html_module.py
+4
-3
common/lib/xmodule/xmodule/modulestore/draft.py
+8
-4
common/lib/xmodule/xmodule/modulestore/xml_exporter.py
+36
-32
common/lib/xmodule/xmodule/modulestore/xml_importer.py
+0
-0
No files found.
cms/djangoapps/contentstore/views.py
View file @
1789814c
...
@@ -1580,7 +1580,8 @@ def import_course(request, org, course, name):
...
@@ -1580,7 +1580,8 @@ def import_course(request, org, course, name):
shutil
.
move
(
r
/
fname
,
course_dir
)
shutil
.
move
(
r
/
fname
,
course_dir
)
module_store
,
course_items
=
import_from_xml
(
modulestore
(
'direct'
),
settings
.
GITHUB_REPO_ROOT
,
module_store
,
course_items
=
import_from_xml
(
modulestore
(
'direct'
),
settings
.
GITHUB_REPO_ROOT
,
[
course_subdir
],
load_error_modules
=
False
,
static_content_store
=
contentstore
(),
target_location_namespace
=
Location
(
location
))
[
course_subdir
],
load_error_modules
=
False
,
static_content_store
=
contentstore
(),
target_location_namespace
=
Location
(
location
),
draft_store
=
modulestore
())
# we can blow this away when we're done importing.
# we can blow this away when we're done importing.
shutil
.
rmtree
(
course_dir
)
shutil
.
rmtree
(
course_dir
)
...
...
common/lib/xmodule/xmodule/html_module.py
View file @
1789814c
...
@@ -118,8 +118,8 @@ class HtmlDescriptor(HtmlFields, XmlDescriptor, EditingDescriptor):
...
@@ -118,8 +118,8 @@ class HtmlDescriptor(HtmlFields, XmlDescriptor, EditingDescriptor):
with
system
.
resources_fs
.
open
(
filepath
)
as
file
:
with
system
.
resources_fs
.
open
(
filepath
)
as
file
:
html
=
file
.
read
()
.
decode
(
'utf-8'
)
html
=
file
.
read
()
.
decode
(
'utf-8'
)
# Log a warning if we can't parse the file, but don't error
# Log a warning if we can't parse the file, but don't error
if
not
check_html
(
html
):
if
not
check_html
(
html
)
and
len
(
html
)
>
0
:
msg
=
"Couldn't parse html in {0}
."
.
format
(
filepath
)
msg
=
"Couldn't parse html in {0}
, content = {1}"
.
format
(
filepath
,
html
)
log
.
warning
(
msg
)
log
.
warning
(
msg
)
system
.
error_tracker
(
"Warning: "
+
msg
)
system
.
error_tracker
(
"Warning: "
+
msg
)
...
@@ -156,7 +156,8 @@ class HtmlDescriptor(HtmlFields, XmlDescriptor, EditingDescriptor):
...
@@ -156,7 +156,8 @@ class HtmlDescriptor(HtmlFields, XmlDescriptor, EditingDescriptor):
resource_fs
.
makedir
(
os
.
path
.
dirname
(
filepath
),
recursive
=
True
,
allow_recreate
=
True
)
resource_fs
.
makedir
(
os
.
path
.
dirname
(
filepath
),
recursive
=
True
,
allow_recreate
=
True
)
with
resource_fs
.
open
(
filepath
,
'w'
)
as
file
:
with
resource_fs
.
open
(
filepath
,
'w'
)
as
file
:
file
.
write
(
self
.
data
.
encode
(
'utf-8'
))
html_data
=
self
.
data
.
encode
(
'utf-8'
)
file
.
write
(
html_data
)
# write out the relative name
# write out the relative name
relname
=
path
(
pathname
)
.
basename
()
relname
=
path
(
pathname
)
.
basename
()
...
...
common/lib/xmodule/xmodule/modulestore/draft.py
View file @
1789814c
...
@@ -106,7 +106,7 @@ class DraftModuleStore(ModuleStoreBase):
...
@@ -106,7 +106,7 @@ class DraftModuleStore(ModuleStoreBase):
"""
"""
return
wrap_draft
(
super
(
DraftModuleStore
,
self
)
.
clone_item
(
source
,
as_draft
(
location
)))
return
wrap_draft
(
super
(
DraftModuleStore
,
self
)
.
clone_item
(
source
,
as_draft
(
location
)))
def
update_item
(
self
,
location
,
data
):
def
update_item
(
self
,
location
,
data
,
allow_not_found
=
False
):
"""
"""
Set the data in the item specified by the location to
Set the data in the item specified by the location to
data
data
...
@@ -115,9 +115,13 @@ class DraftModuleStore(ModuleStoreBase):
...
@@ -115,9 +115,13 @@ class DraftModuleStore(ModuleStoreBase):
data: A nested dictionary of problem data
data: A nested dictionary of problem data
"""
"""
draft_loc
=
as_draft
(
location
)
draft_loc
=
as_draft
(
location
)
draft_item
=
self
.
get_item
(
location
)
try
:
if
not
getattr
(
draft_item
,
'is_draft'
,
False
):
draft_item
=
self
.
get_item
(
location
)
self
.
clone_item
(
location
,
draft_loc
)
if
not
getattr
(
draft_item
,
'is_draft'
,
False
):
self
.
clone_item
(
location
,
draft_loc
)
except
ItemNotFoundError
,
e
:
if
not
allow_not_found
:
raise
e
return
super
(
DraftModuleStore
,
self
)
.
update_item
(
draft_loc
,
data
)
return
super
(
DraftModuleStore
,
self
)
.
update_item
(
draft_loc
,
data
)
...
...
common/lib/xmodule/xmodule/modulestore/xml_exporter.py
View file @
1789814c
...
@@ -8,55 +8,59 @@ from json import dumps
...
@@ -8,55 +8,59 @@ from json import dumps
def
export_to_xml
(
modulestore
,
contentstore
,
course_location
,
root_dir
,
course_dir
,
draft_modulestore
=
None
):
def
export_to_xml
(
modulestore
,
contentstore
,
course_location
,
root_dir
,
course_dir
,
draft_modulestore
=
None
):
course
=
modulestore
.
get_item
(
course_location
)
course
=
modulestore
.
get_item
(
course_location
)
fs
=
OSFS
(
root_dir
)
fs
=
OSFS
(
root_dir
)
export_fs
=
fs
.
makeopendir
(
course_dir
)
export_fs
=
fs
.
makeopendir
(
course_dir
)
xml
=
course
.
export_to_xml
(
export_fs
)
xml
=
course
.
export_to_xml
(
export_fs
)
with
export_fs
.
open
(
'course.xml'
,
'w'
)
as
course_xml
:
with
export_fs
.
open
(
'course.xml'
,
'w'
)
as
course_xml
:
course_xml
.
write
(
xml
)
course_xml
.
write
(
xml
)
# export the static assets
# export the static assets
contentstore
.
export_all_for_course
(
course_location
,
root_dir
+
'/'
+
course_dir
+
'/static/'
)
contentstore
.
export_all_for_course
(
course_location
,
root_dir
+
'/'
+
course_dir
+
'/static/'
)
# export the static tabs
# export the static tabs
export_extra_content
(
export_fs
,
modulestore
,
course_location
,
'static_tab'
,
'tabs'
,
'.html'
)
export_extra_content
(
export_fs
,
modulestore
,
course_location
,
'static_tab'
,
'tabs'
,
'.html'
)
# export the custom tags
# export the custom tags
export_extra_content
(
export_fs
,
modulestore
,
course_location
,
'custom_tag_template'
,
'custom_tags'
)
export_extra_content
(
export_fs
,
modulestore
,
course_location
,
'custom_tag_template'
,
'custom_tags'
)
# export the course updates
# export the course updates
export_extra_content
(
export_fs
,
modulestore
,
course_location
,
'course_info'
,
'info'
,
'.html'
)
export_extra_content
(
export_fs
,
modulestore
,
course_location
,
'course_info'
,
'info'
,
'.html'
)
# export the grading policy
# export the grading policy
policies_dir
=
export_fs
.
makeopendir
(
'policies'
)
policies_dir
=
export_fs
.
makeopendir
(
'policies'
)
course_run_policy_dir
=
policies_dir
.
makeopendir
(
course
.
location
.
name
)
course_run_policy_dir
=
policies_dir
.
makeopendir
(
course
.
location
.
name
)
with
course_run_policy_dir
.
open
(
'grading_policy.json'
,
'w'
)
as
grading_policy
:
with
course_run_policy_dir
.
open
(
'grading_policy.json'
,
'w'
)
as
grading_policy
:
grading_policy
.
write
(
dumps
(
course
.
grading_policy
))
grading_policy
.
write
(
dumps
(
course
.
grading_policy
))
# export all of the course metadata in policy.json
# export all of the course metadata in policy.json
with
course_run_policy_dir
.
open
(
'policy.json'
,
'w'
)
as
course_policy
:
with
course_run_policy_dir
.
open
(
'policy.json'
,
'w'
)
as
course_policy
:
policy
=
{
'course/'
+
course
.
location
.
name
:
own_metadata
(
course
)}
policy
=
{
'course/'
+
course
.
location
.
name
:
own_metadata
(
course
)}
course_policy
.
write
(
dumps
(
policy
))
course_policy
.
write
(
dumps
(
policy
))
# export everything from the draft store, unfortunately this will create lots of duplicates
# export everything from the draft store, unfortunately this will create lots of duplicates
'''
if draft_modulestore is not None:
if draft_modulestore is not None:
draft_course = draft_modulestore.get_item(course_location)
draft_course = draft_modulestore.get_item(course_location)
draft_course_dir
=
export_fs
.
makeopendir
(
'drafts'
)
xml = draft_course.export_to_xml(draft_course_dir)
xml = draft_course.export_to_xml(draft_course_dir)
with draft_course_dir.open('course.xml', 'w') as course_xml:
with draft_course_dir.open('course.xml', 'w') as course_xml:
course_xml.write(xml)
course_xml.write(xml)
'''
'''
draft_items = modulestore.get_items([None, None, None, 'vertical', None, 'draft'])
logging.debug('draft_items = {0}'.format(draft_items))
# export draft content
if len(draft_items) > 0:
# NOTE: this code assumes that verticals are the top most draftable container
# should we change the application, then this assumption will no longer
# be valid
draft_items
=
draft_modulestore
.
get_items
([
None
,
course_location
.
org
,
course_location
.
course
,
'vertical'
,
None
,
'draft'
])
if
len
(
draft_items
)
>
0
:
draft_course_dir
=
export_fs
.
makeopendir
(
'drafts'
)
for
draft_item
in
draft_items
:
for
draft_item
in
draft_items
:
draft_item.export_to_xml(draft_items_dir)
draft_item
.
export_to_xml
(
draft_course_dir
)
#with draft_items_dir.open(draft_item.location.name + '.xml', 'w'):
'''
def
export_extra_content
(
export_fs
,
modulestore
,
course_location
,
category_type
,
dirname
,
file_suffix
=
''
):
def
export_extra_content
(
export_fs
,
modulestore
,
course_location
,
category_type
,
dirname
,
file_suffix
=
''
):
...
...
common/lib/xmodule/xmodule/modulestore/xml_importer.py
View file @
1789814c
This diff is collapsed.
Click to expand it.
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