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
1a0220c7
Commit
1a0220c7
authored
Feb 27, 2013
by
Arthur Barrett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added a validation check on the input choice attribute
parent
44a68e69
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
2 deletions
+15
-2
common/lib/capa/capa/inputtypes.py
+13
-1
common/lib/capa/capa/responsetypes.py
+2
-1
No files found.
common/lib/capa/capa/inputtypes.py
View file @
1a0220c7
...
...
@@ -974,6 +974,7 @@ class AnnotationInput(InputTypeBase):
xml
=
self
.
xml
self
.
debug
=
False
# set to True to display extra debug info with input
self
.
return_to_annotation
=
True
# return only works in conjunction with annotatable xmodule
self
.
title
=
xml
.
findtext
(
'./title'
,
'Annotation Exercise'
)
self
.
text
=
xml
.
findtext
(
'./text'
)
...
...
@@ -981,13 +982,14 @@ class AnnotationInput(InputTypeBase):
self
.
comment_prompt
=
xml
.
findtext
(
'./comment_prompt'
,
'Type a commentary below:'
)
self
.
tag_prompt
=
xml
.
findtext
(
'./tag_prompt'
,
'Select one or more tags:'
)
self
.
options
=
self
.
_find_options
()
self
.
return_to_annotation
=
True
# return only works in conjunction with annotatable xmodule
# Need to provide a value that JSON can parse if there is no
# student-supplied value yet.
if
self
.
value
==
''
:
self
.
value
=
'null'
self
.
_validate_options
()
def
_find_options
(
self
):
''' Returns an array of dicts where each dict represents an option. '''
elements
=
self
.
xml
.
findall
(
'./options/option'
)
...
...
@@ -997,6 +999,16 @@ class AnnotationInput(InputTypeBase):
'choice'
:
option
.
get
(
'choice'
)
}
for
(
index
,
option
)
in
enumerate
(
elements
)
]
def
_validate_options
(
self
):
''' Raises a ValueError if the choice attribute is missing or invalid. '''
valid_choices
=
(
'correct'
,
'partially-correct'
,
'incorrect'
)
for
option
in
self
.
options
:
choice
=
option
[
'choice'
]
if
choice
is
None
:
raise
ValueError
(
'Missing required choice attribute.'
)
elif
choice
not
in
valid_choices
:
raise
ValueError
(
'Invalid choice attribute: {0}. Must be one of: {1}'
.
format
(
choice
,
', '
.
join
(
valid_choices
)))
def
_unpack
(
self
,
json_value
):
''' Unpacks the json input state into a dict. '''
d
=
json
.
loads
(
json_value
)
...
...
common/lib/capa/capa/responsetypes.py
View file @
1a0220c7
...
...
@@ -1881,7 +1881,8 @@ class AnnotationResponse(LoncapaResponse):
answer_map
=
{}
for
inputfield
in
self
.
inputfields
:
correct_option
=
self
.
_find_option_with_choice
(
inputfield
,
'correct'
)
answer_map
[
inputfield
.
get
(
'id'
)]
=
correct_option
[
'description'
]
if
correct_option
is
not
None
:
answer_map
[
inputfield
.
get
(
'id'
)]
=
correct_option
.
get
(
'description'
)
return
answer_map
def
_find_options
(
self
,
inputfield
):
...
...
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