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
552c1997
Commit
552c1997
authored
Jun 30, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Export large xml as separate files. Note: inherited metadata is creeping into child nodes
parent
bacce3e6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
18 deletions
+21
-18
common/lib/xmodule/html_module.py
+0
-6
common/lib/xmodule/xml_module.py
+21
-12
No files found.
common/lib/xmodule/html_module.py
View file @
552c1997
import
json
import
logging
from
xmodule.x_module
import
XModule
from
xmodule.raw_module
import
RawDescriptor
from
lxml
import
etree
from
pkg_resources
import
resource_string
log
=
logging
.
getLogger
(
"mitx.courseware"
)
...
...
@@ -28,7 +26,3 @@ class HtmlDescriptor(RawDescriptor):
js
=
{
'coffee'
:
[
resource_string
(
__name__
,
'js/module/html.coffee'
)]}
js_module
=
'HTML'
@classmethod
def
definition_from_file
(
cls
,
file
,
system
):
return
{
'data'
:
file
.
read
()}
common/lib/xmodule/xml_module.py
View file @
552c1997
...
...
@@ -70,16 +70,6 @@ class XmlDescriptor(XModuleDescriptor):
raise
NotImplementedError
(
"
%
s does not implement definition_from_xml"
%
cls
.
__name__
)
@classmethod
def
definition_from_file
(
cls
,
file
,
system
):
"""
Return the definition to be passed to the newly created descriptor
during from_xml
file: File pointer
"""
return
cls
.
definition_from_xml
(
etree
.
parse
(
file
),
system
)
@classmethod
def
from_xml
(
cls
,
xml_data
,
system
,
org
=
None
,
course
=
None
):
"""
Creates an instance of this descriptor from the supplied xml_data.
...
...
@@ -113,8 +103,9 @@ class XmlDescriptor(XModuleDescriptor):
if
filename
is
None
:
return
cls
.
definition_from_xml
(
xml_object
,
system
)
else
:
filepath
=
'{type}/{name}.{ext}'
.
format
(
type
=
xml_object
.
tag
,
name
=
filename
,
ext
=
cls
.
filename_extension
)
return
cls
.
definition_from_file
(
system
.
resources_fs
.
open
(
filepath
),
system
)
filepath
=
cls
.
_format_filepath
(
xml_object
.
tag
,
filename
)
with
system
.
resources_fs
.
open
(
filepath
)
as
file
:
return
cls
.
definition_from_xml
(
etree
.
parse
(
file
)
.
getroot
(),
system
)
return
cls
(
system
,
...
...
@@ -127,6 +118,10 @@ class XmlDescriptor(XModuleDescriptor):
metadata
=
LazyLoadingDict
(
metadata_loader
),
)
@classmethod
def
_format_filepath
(
cls
,
type
,
name
):
return
'{type}/{name}.{ext}'
.
format
(
type
=
type
,
name
=
name
,
ext
=
cls
.
filename_extension
)
def
export_to_xml
(
self
,
resource_fs
):
"""
Returns an xml string representing this module, and all modules underneath it.
...
...
@@ -139,6 +134,20 @@ class XmlDescriptor(XModuleDescriptor):
using the from_xml method with the same system, org, and course
"""
xml_object
=
self
.
definition_to_xml
(
resource_fs
)
# Put content in a separate file if it's large (has more than 5 descendent tags)
if
len
(
list
(
xml_object
.
iter
()))
>
5
:
filepath
=
self
.
__class__
.
_format_filepath
(
self
.
type
,
self
.
name
)
resource_fs
.
makedir
(
self
.
type
,
allow_recreate
=
True
)
with
resource_fs
.
open
(
filepath
,
'w'
)
as
file
:
file
.
write
(
etree
.
tostring
(
xml_object
,
pretty_print
=
True
))
for
child
in
xml_object
:
xml_object
.
remove
(
child
)
xml_object
.
set
(
'filename'
,
self
.
name
)
xml_object
.
set
(
'slug'
,
self
.
name
)
xml_object
.
tag
=
self
.
type
...
...
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