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
7f6f04df
Commit
7f6f04df
authored
Jul 31, 2012
by
Mike Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
not yet completed CapaXML -> Wiki
parent
75eca718
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
124 additions
and
0 deletions
+124
-0
cms/djangoapps/contentstore/management/commands/convert.py
+64
-0
format.ref
+60
-0
No files found.
cms/djangoapps/contentstore/management/commands/convert.py
0 → 100644
View file @
7f6f04df
###
### One-off script for importing courseware form XML format
###
from
django.core.management.base
import
BaseCommand
,
CommandError
import
json
from
lxml
import
etree
class
CapaXMLConverter
(
object
):
def
convert_from_xml
(
self
,
filename
):
out
=
{
'scripts'
:
[],
'contents'
:
[]}
temp
=
{
'text'
:
''
,
'response'
:
None
}
with
open
(
filename
,
"r"
)
as
f
:
for
event
,
element
in
etree
.
iterparse
(
f
,
events
=
(
"start"
,
"end"
)):
if
event
==
"start"
and
element
.
tag
==
"br"
:
temp
[
'text'
]
+=
'
\n\n
'
elif
event
==
"start"
and
element
.
text
:
temp
[
'text'
]
+=
element
.
text
elif
event
==
"end"
and
element
.
tail
:
temp
[
'text'
]
+=
element
.
tail
if
event
==
"start"
:
if
element
.
tag
==
'multiplechoiceresponse'
:
temp
[
'group'
]
=
{
'type'
:
'multiple_choice'
,
'choices'
:
[]}
elif
element
.
tag
==
'truefalseresponse'
:
temp
[
'group'
]
=
{
'type'
:
'true_false'
,
'statements'
:
[]}
elif
element
.
tag
==
"choice"
:
if
temp
[
'group'
][
'type'
]
==
'multiple_choice'
:
temp
[
'response'
]
=
{
'type'
:
'choice'
,
'text'
:
''
,
'correct'
:
element
.
get
(
'correct'
)
==
"true"
}
elif
temp
[
'group'
][
'type'
]
==
'true_false'
:
temp
[
'response'
]
=
{
'type'
:
'statement'
,
'text'
:
''
,
'correct'
:
element
.
get
(
'correct'
)
==
"true"
}
elif
event
==
"end"
:
if
element
.
tag
==
"endouttext"
:
if
temp
[
'response'
]:
temp
[
'response'
][
'text'
]
+=
temp
[
'text'
]
.
strip
()
else
:
out
[
'contents'
]
.
append
({
'type'
:
'paragraph'
,
'text'
:
temp
[
'text'
]
.
strip
()})
temp
[
'text'
]
=
''
elif
element
.
tag
in
[
"multiplechoiceresponse"
,
"truefalseresponse"
]:
out
[
'contents'
]
.
append
(
temp
[
'group'
])
temp
[
'group'
]
=
None
elif
element
.
tag
==
"choice"
:
if
temp
[
'group'
][
'type'
]
==
'true_false'
:
temp
[
'group'
][
'statements'
]
.
append
(
temp
[
'response'
])
elif
temp
[
'group'
][
'type'
]
==
'multiple_choice'
:
temp
[
'group'
][
'choices'
]
.
append
(
temp
[
'response'
])
temp
[
'response'
]
=
None
# self.parse_tree(tree, out)
return
out
class
Command
(
BaseCommand
):
help
=
\
'''Import the specified data directory into the default ModuleStore'''
def
handle
(
self
,
*
args
,
**
options
):
self
.
converter
=
CapaXMLConverter
()
# print json.dumps(self.converter.convert_from_xml("/Users/ccp/code/mitx_all/data/6.002x/problems/HW3ID1.xml"), indent=2)
print
json
.
dumps
(
self
.
converter
.
convert_from_xml
(
"/Users/ccp/code/mitx_all/data/6.002x/problems/multichoice.xml"
),
indent
=
2
)
format.ref
0 → 100644
View file @
7f6f04df
- scripts:
- type: 'script'
language: 'python'
code: 'print "Hello world!"'
- contents:
- type: 'text'
text: 'This is a sample paragraph. The linebreaks here should matter..?'
- type: 'linebreaks'
count: 2
- type: 'multiple_choice'
randomize: true
choices:
- type: 'choice'
text: 'Choice A'
correct: true
- type: 'choice'
text: 'Choice B'
correct: false
- type: 'choice'
text: 'Choice C'
correct: true
- type: 'true_false'
statements:
- type: 'statement'
text: 'Sun revolves around Earth. '
correct: false
- type: 'statement'
text: 'This is a true statement. '
correct: true
- type: 'string'
answer: 'banana'
- type: 'numerical'
tolerance: '5%'
answer: 6
- type: 'formula'
answer: '-A*(RF/RS)'
samples: 10
tolerance: '5%'
variables:
- type: 'variable'
symbol: 'A'
range: '1-3'
- type: 'variable'
symbol: 'RF'
range: '1-3'
- type: 'variable'
symbol: 'RS'
range: '1-3'
- type: 'variable'
symbol: 'L'
range: '1-3'
- type: 'variable'
symbol: 'T'
range: '1-3'
- type: 'custom'
script:
- type: 'script'
language: 'python'
code: 'correct = true'
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