Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-ora2
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-ora2
Commits
e0628b79
Commit
e0628b79
authored
Mar 10, 2014
by
Will Daly
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #97 from edx/will/export-xml
Allow export of OpenAssessmentBlock to XML
parents
dcecf0ed
202e467b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
4 deletions
+53
-4
apps/openassessment/xblock/openassessmentblock.py
+7
-1
apps/openassessment/xblock/test/test_export_import.py
+27
-0
apps/openassessment/xblock/xml.py
+19
-3
No files found.
apps/openassessment/xblock/openassessmentblock.py
View file @
e0628b79
...
...
@@ -19,7 +19,7 @@ from openassessment.xblock.peer_assessment_mixin import PeerAssessmentMixin
from
openassessment.xblock.self_assessment_mixin
import
SelfAssessmentMixin
from
openassessment.xblock.submission_mixin
import
SubmissionMixin
from
openassessment.xblock.studio_mixin
import
StudioMixin
from
openassessment.xblock.xml
import
update_from_xml
from
openassessment.xblock.xml
import
update_from_xml
,
serialize_content_to_xml
from
openassessment.xblock.workflow_mixin
import
WorkflowMixin
from
openassessment.workflow
import
api
as
workflow_api
from
openassessment.xblock.validation
import
validator
...
...
@@ -380,6 +380,12 @@ class OpenAssessmentBlock(
context
=
Context
(
context_dict
)
return
Response
(
template
.
render
(
context
),
content_type
=
'application/html'
,
charset
=
'UTF-8'
)
def
add_xml_to_node
(
self
,
node
):
"""
Serialize the XBlock to XML for exporting.
"""
serialize_content_to_xml
(
self
,
node
)
def
render_error
(
self
,
error_msg
):
"""
Render an error message.
...
...
apps/openassessment/xblock/test/test_export_import.py
0 → 100644
View file @
e0628b79
"""
Test that we can export a block from the runtime (to XML) and re-import it without error.
"""
import
copy
from
StringIO
import
StringIO
from
.base
import
XBlockHandlerTestCase
,
scenario
class
TestExportImport
(
XBlockHandlerTestCase
):
@scenario
(
'data/basic_scenario.xml'
)
def
test_export_import
(
self
,
xblock
):
# Store the fields of the XBlock
old_fields
=
copy
.
deepcopy
(
xblock
.
fields
)
# Export the XBlock from the runtime
output_buffer
=
StringIO
()
self
.
runtime
.
export_to_xml
(
xblock
,
output_buffer
)
# Re-import the XBlock
block_id
=
self
.
runtime
.
parse_xml_string
(
output_buffer
.
getvalue
(),
self
.
runtime
.
id_generator
)
new_block
=
self
.
runtime
.
get_block
(
block_id
)
# Check that the values of all fields are the same
self
.
assertItemsEqual
(
new_block
.
fields
,
old_fields
)
apps/openassessment/xblock/xml.py
View file @
e0628b79
...
...
@@ -365,17 +365,19 @@ def _parse_assessments_xml(assessments_root, start, due):
return
assessments_list
def
serialize_content
(
oa_block
):
def
serialize_content
_to_xml
(
oa_block
,
root
):
"""
Serialize the OpenAssessment XBlock's content to XML.
Args:
oa_block (OpenAssessmentBlock): The open assessment block to serialize.
root (etree.Element): The XML root node to update.
Returns:
xml (unicode)
etree.Element
"""
root
=
etree
.
Element
(
'openassessment'
)
root
.
tag
=
'openassessment'
# Set submission due date
if
oa_block
.
submission_due
is
not
None
:
...
...
@@ -410,6 +412,20 @@ def serialize_content(oa_block):
rubric_root
=
etree
.
SubElement
(
root
,
'rubric'
)
_serialize_rubric
(
rubric_root
,
oa_block
)
def
serialize_content
(
oa_block
):
"""
Serialize the OpenAssessment XBlock's content to an XML string.
Args:
oa_block (OpenAssessmentBlock): The open assessment block to serialize.
Returns:
xml (unicode)
"""
root
=
etree
.
Element
(
'openassessment'
)
serialize_content_to_xml
(
oa_block
,
root
)
# Return a UTF-8 representation of the XML
return
etree
.
tostring
(
root
,
pretty_print
=
True
,
encoding
=
'utf-8'
)
...
...
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