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
f375258b
Commit
f375258b
authored
Jun 29, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add xml export infrastructure for all existing modules
parent
a94e4d2f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
0 deletions
+60
-0
common/lib/xmodule/abtest_module.py
+18
-0
common/lib/xmodule/raw_module.py
+3
-0
common/lib/xmodule/seq_module.py
+6
-0
common/lib/xmodule/xml_module.py
+33
-0
No files found.
common/lib/xmodule/abtest_module.py
View file @
f375258b
...
...
@@ -103,3 +103,21 @@ class ABTestDescriptor(RawDescriptor, XmlDescriptor):
definition
[
'data'
][
'group_portions'
][
DEFAULT
]
=
default_portion
return
definition
def
definition_to_xml
(
self
,
resource_fs
):
xml_object
=
etree
.
Element
(
'abtest'
)
xml_object
.
set
(
'experiment'
,
self
.
definition
[
'data'
][
'experiment'
])
for
name
,
group
in
self
.
definition
[
'data'
][
'group_content'
]
.
items
():
if
name
==
DEFAULT
:
group_elem
=
etree
.
SubElement
(
xml_object
,
'default'
)
else
:
group_elem
=
etree
.
SubElement
(
xml_object
,
'group'
,
attrib
=
{
'portion'
:
str
(
self
.
definition
[
'data'
][
'group_portions'
][
name
]),
'name'
:
name
,
})
for
child_loc
in
group
:
child
=
self
.
system
.
load_item
(
child_loc
)
group_elem
.
append
(
etree
.
fromstring
(
child
.
export_to_xml
(
resource_fs
)))
return
xml_object
common/lib/xmodule/raw_module.py
View file @
f375258b
...
...
@@ -21,3 +21,6 @@ class RawDescriptor(MakoModuleDescriptor, XmlDescriptor):
@classmethod
def
definition_from_xml
(
cls
,
xml_object
,
system
):
return
{
'data'
:
etree
.
tostring
(
xml_object
)}
def
definition_to_xml
(
self
,
resource_fs
):
return
etree
.
fromstring
(
self
.
definition
[
'data'
])
common/lib/xmodule/seq_module.py
View file @
f375258b
...
...
@@ -108,3 +108,9 @@ class SequenceDescriptor(MakoModuleDescriptor, XmlDescriptor):
system
.
process_xml
(
etree
.
tostring
(
child_module
))
.
location
.
url
()
for
child_module
in
xml_object
]}
def
definition_to_xml
(
self
,
resource_fs
):
xml_object
=
etree
.
Element
(
'sequential'
)
for
child
in
self
.
get_children
():
xml_object
.
append
(
etree
.
fromstring
(
child
.
export_to_xml
(
resource_fs
)))
return
xml_object
common/lib/xmodule/xml_module.py
View file @
f375258b
...
...
@@ -51,3 +51,36 @@ class XmlDescriptor(XModuleDescriptor):
xml_object
.
get
(
'slug'
)],
metadata
=
metadata
,
)
def
export_to_xml
(
self
,
resource_fs
):
"""
Returns an xml string representing this module, and all modules underneath it.
May also write required resources out to resource_fs
Assumes that modules have single parantage (that no module appears twice in the same course),
and that it is thus safe to nest modules as xml children as appropriate.
The returned XML should be able to be parsed back into an identical XModuleDescriptor
using the from_xml method with the same system, org, and course
"""
xml_object
=
self
.
definition_to_xml
(
resource_fs
)
xml_object
.
set
(
'slug'
,
self
.
name
)
xml_object
.
tag
=
self
.
type
for
attr
in
(
'format'
,
'graceperiod'
,
'showanswer'
,
'rerandomize'
,
'due'
):
if
attr
in
self
.
metadata
:
xml_object
.
set
(
attr
,
self
.
metadata
[
attr
])
if
'graded'
in
self
.
metadata
:
xml_object
.
set
(
'graded'
,
str
(
self
.
metadata
[
'graded'
])
.
lower
())
if
'display_name'
in
self
.
metadata
:
xml_object
.
set
(
'name'
,
self
.
metadata
[
'display_name'
])
return
etree
.
tostring
(
xml_object
,
pretty_print
=
True
)
def
definition_to_xml
(
self
,
resource_fs
):
"""
Return a new etree Element object created from this modules definition.
"""
raise
NotImplementedError
(
"
%
s does not implement definition_to_xml"
%
self
.
__class__
.
__name__
)
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