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
c1324ec2
Commit
c1324ec2
authored
Feb 27, 2013
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modified CodeResponse to use XML factory
parent
6e4c418a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
18 deletions
+68
-18
common/lib/capa/capa/tests/response_xml_factory.py
+67
-18
common/lib/capa/capa/tests/test_files/filename_convert_test.txt
+1
-0
common/lib/capa/capa/tests/test_responsetypes.py
+0
-0
No files found.
common/lib/capa/capa/tests/response_xml_factory.py
View file @
c1324ec2
...
...
@@ -43,6 +43,8 @@ class ResponseXMLFactory(object):
*script*: The embedded Python script (a string)
*num_responses*: The number of responses to create [DEFAULT: 1]
*num_inputs*: The number of input elements
to create [DEFAULT: 1]
...
...
@@ -53,6 +55,7 @@ class ResponseXMLFactory(object):
question_text
=
kwargs
.
get
(
'question_text'
,
''
)
explanation_text
=
kwargs
.
get
(
'explanation_text'
,
''
)
script
=
kwargs
.
get
(
'script'
,
None
)
num_responses
=
kwargs
.
get
(
'num_responses'
,
1
)
num_inputs
=
kwargs
.
get
(
'num_inputs'
,
1
)
# The root is <problem>
...
...
@@ -68,20 +71,23 @@ class ResponseXMLFactory(object):
question
=
etree
.
SubElement
(
root
,
"p"
)
question
.
text
=
question_text
# Add the response
response_element
=
self
.
create_response_element
(
**
kwargs
)
root
.
append
(
response_element
)
# Add input elements
for
i
in
range
(
0
,
int
(
num_inputs
)):
input_element
=
self
.
create_input_element
(
**
kwargs
)
response_element
.
append
(
input_element
)
# The problem has an explanation of the solution
explanation
=
etree
.
SubElement
(
root
,
"solution"
)
explanation_div
=
etree
.
SubElement
(
explanation
,
"div"
)
explanation_div
.
set
(
"class"
,
"detailed-solution"
)
explanation_div
.
text
=
explanation_text
# Add the response(s)
for
i
in
range
(
0
,
int
(
num_responses
)):
response_element
=
self
.
create_response_element
(
**
kwargs
)
root
.
append
(
response_element
)
# Add input elements
for
j
in
range
(
0
,
int
(
num_inputs
)):
input_element
=
self
.
create_input_element
(
**
kwargs
)
if
not
(
None
==
input_element
):
response_element
.
append
(
input_element
)
# The problem has an explanation of the solution
if
explanation_text
:
explanation
=
etree
.
SubElement
(
root
,
"solution"
)
explanation_div
=
etree
.
SubElement
(
explanation
,
"div"
)
explanation_div
.
set
(
"class"
,
"detailed-solution"
)
explanation_div
.
text
=
explanation_text
return
etree
.
tostring
(
root
)
...
...
@@ -271,13 +277,56 @@ class SchematicResponseXMLFactory(ResponseXMLFactory):
class
CodeResponseXMLFactory
(
ResponseXMLFactory
):
""" Factory for creating <coderesponse> XML trees """
def
build_xml
(
self
,
**
kwargs
):
# Since we are providing an <answer> tag,
# we should override the default behavior
# of including a <solution> tag as well
kwargs
[
'explanation_text'
]
=
None
return
super
(
CodeResponseXMLFactory
,
self
)
.
build_xml
(
**
kwargs
)
def
create_response_element
(
self
,
**
kwargs
):
""" Create a <coderesponse> XML element """
raise
NotImplemented
""" Create a <coderesponse> XML element:
Uses **kwargs:
*initial_display*: The code that initially appears in the textbox
[DEFAULT: "Enter code here"]
*answer_display*: The answer to display to the student
[DEFAULT: "This is the correct answer!"]
*grader_payload*: A JSON-encoded string sent to the grader
[DEFAULT: empty dict string]
"""
# Get **kwargs
initial_display
=
kwargs
.
get
(
"initial_display"
,
"Enter code here"
)
answer_display
=
kwargs
.
get
(
"answer_display"
,
"This is the correct answer!"
)
grader_payload
=
kwargs
.
get
(
"grader_payload"
,
'{}'
)
def
create_input_element
(
self
,
**
kwargs
):
raise
NotImplemented
# Create the <coderesponse> element
response_element
=
etree
.
Element
(
"coderesponse"
)
codeparam_element
=
etree
.
SubElement
(
response_element
,
"codeparam"
)
# Set the initial display text
initial_element
=
etree
.
SubElement
(
codeparam_element
,
"initial_display"
)
initial_element
.
text
=
str
(
initial_display
)
# Set the answer display text
answer_element
=
etree
.
SubElement
(
codeparam_element
,
"answer_display"
)
answer_element
.
text
=
str
(
answer_display
)
# Set the grader payload string
grader_element
=
etree
.
SubElement
(
codeparam_element
,
"grader_payload"
)
grader_element
.
text
=
str
(
grader_payload
)
# Create the input within the response
input_element
=
etree
.
SubElement
(
response_element
,
"textbox"
)
input_element
.
set
(
"mode"
,
"python"
)
return
response_element
def
create_input_element
(
self
,
**
kwargs
):
# Since we create this in create_response_element(),
# return None here
return
None
class
ChoiceResponseXMLFactory
(
ResponseXMLFactory
):
""" Factory for creating <choiceresponse> XML trees """
...
...
common/lib/capa/capa/tests/test_files/filename_convert_test.txt
0 → 100644
View file @
c1324ec2
This file is used to test converting file handles to filenames in the capa utility module
common/lib/capa/capa/tests/test_responsetypes.py
View file @
c1324ec2
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