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
0086893d
Commit
0086893d
authored
Feb 12, 2015
by
Waheed Ahmed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed option was not remain selected after submitting.
TNL-1419
parent
73c30993
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
1 deletions
+44
-1
common/lib/capa/capa/capa_problem.py
+3
-0
common/lib/capa/capa/correctmap.py
+2
-0
common/lib/capa/capa/inputtypes.py
+3
-0
common/lib/capa/capa/responsetypes.py
+15
-0
common/lib/capa/capa/templates/optioninput.html
+1
-1
common/lib/capa/capa/tests/test_responsetypes.py
+20
-0
No files found.
common/lib/capa/capa/capa_problem.py
View file @
0086893d
...
...
@@ -710,12 +710,14 @@ class LoncapaProblem(object):
hint
=
''
hintmode
=
None
input_id
=
problemtree
.
get
(
'id'
)
answervariable
=
None
if
problemid
in
self
.
correct_map
:
pid
=
input_id
status
=
self
.
correct_map
.
get_correctness
(
pid
)
msg
=
self
.
correct_map
.
get_msg
(
pid
)
hint
=
self
.
correct_map
.
get_hint
(
pid
)
hintmode
=
self
.
correct_map
.
get_hintmode
(
pid
)
answervariable
=
self
.
correct_map
.
get_property
(
pid
,
'answervariable'
)
value
=
""
if
self
.
student_answers
and
problemid
in
self
.
student_answers
:
...
...
@@ -730,6 +732,7 @@ class LoncapaProblem(object):
'status'
:
status
,
'id'
:
input_id
,
'input_state'
:
self
.
input_state
[
input_id
],
'answervariable'
:
answervariable
,
'feedback'
:
{
'message'
:
msg
,
'hint'
:
hint
,
...
...
common/lib/capa/capa/correctmap.py
View file @
0086893d
...
...
@@ -46,6 +46,7 @@ class CorrectMap(object):
hint
=
''
,
hintmode
=
None
,
queuestate
=
None
,
answervariable
=
None
,
# pylint: disable=C0330
**
kwargs
):
...
...
@@ -57,6 +58,7 @@ class CorrectMap(object):
'hint'
:
hint
,
'hintmode'
:
hintmode
,
'queuestate'
:
queuestate
,
'answervariable'
:
answervariable
,
}
def
__repr__
(
self
):
...
...
common/lib/capa/capa/inputtypes.py
View file @
0086893d
...
...
@@ -213,6 +213,7 @@ class InputTypeBase(object):
self
.
hint
=
feedback
.
get
(
'hint'
,
''
)
self
.
hintmode
=
feedback
.
get
(
'hintmode'
,
None
)
self
.
input_state
=
state
.
get
(
'input_state'
,
{})
self
.
answervariable
=
state
.
get
(
"answervariable"
,
None
)
# put hint above msg if it should be displayed
if
self
.
hintmode
==
'always'
:
...
...
@@ -310,6 +311,8 @@ class InputTypeBase(object):
(
a
,
v
)
for
(
a
,
v
)
in
self
.
loaded_attributes
.
iteritems
()
if
a
in
self
.
to_render
)
context
.
update
(
self
.
_extra_context
())
if
self
.
answervariable
:
context
.
update
({
'answervariable'
:
self
.
answervariable
})
return
context
def
_extra_context
(
self
):
...
...
common/lib/capa/capa/responsetypes.py
View file @
0086893d
...
...
@@ -1097,6 +1097,9 @@ class OptionResponse(LoncapaResponse):
cmap
.
set
(
aid
,
'correct'
)
else
:
cmap
.
set
(
aid
,
'incorrect'
)
answer_variable
=
self
.
get_student_answer_variable_name
(
student_answers
,
aid
)
if
answer_variable
:
cmap
.
set_property
(
aid
,
'answervariable'
,
answer_variable
)
return
cmap
def
get_answers
(
self
):
...
...
@@ -1105,6 +1108,18 @@ class OptionResponse(LoncapaResponse):
# log.debug('%s: expected answers=%s' % (unicode(self),amap))
return
amap
def
get_student_answer_variable_name
(
self
,
student_answers
,
aid
):
"""
Return student answers variable name if exist in context else None.
"""
if
aid
in
student_answers
:
for
key
,
val
in
self
.
context
.
iteritems
():
# convert val into unicode because student answer always be a unicode string
# even it is a list, dict etc.
if
unicode
(
val
)
==
student_answers
[
aid
]:
return
'$'
+
key
return
None
#-----------------------------------------------------------------------------
...
...
common/lib/capa/capa/templates/optioninput.html
View file @
0086893d
...
...
@@ -5,7 +5,7 @@
<option
value=
"option_${id}_dummy_default"
>
</option>
% for option_id, option_description in options:
<option
value=
"${option_id}"
%
if
(
option_id=
=value):
%
if
(
option_id=
=value
or
option_id=
=answervariable
):
selected=
"true"
%
endif
>
${option_description}
</option>
...
...
common/lib/capa/capa/tests/test_responsetypes.py
View file @
0086893d
...
...
@@ -347,6 +347,26 @@ class OptionResponseTest(ResponseTest):
self
.
assert_grade
(
problem
,
"hasn
\'
t"
,
"correct"
)
self
.
assert_grade
(
problem
,
"has'nt"
,
"incorrect"
)
def
test_variable_options
(
self
):
"""
Test that if variable are given in option response then correct map must contain answervariable value.
"""
script
=
textwrap
.
dedent
(
"""
\
a = 1000
b = a*2
c = a*3
"""
)
problem
=
self
.
build_problem
(
options
=
[
'$a'
,
'$b'
,
'$c'
],
correct_option
=
'$a'
,
script
=
script
)
input_dict
=
{
'1_2_1'
:
'1000'
}
correct_map
=
problem
.
grade_answers
(
input_dict
)
self
.
assertEqual
(
correct_map
.
get_correctness
(
'1_2_1'
),
'correct'
)
self
.
assertEqual
(
correct_map
.
get_property
(
'1_2_1'
,
'answervariable'
),
'$a'
)
class
FormulaResponseTest
(
ResponseTest
):
"""
...
...
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