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
81c4e4f7
Commit
81c4e4f7
authored
Feb 21, 2013
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make check_function more flexible so symbolicresponse can pass in more information.
parent
42eee48e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
5 deletions
+13
-5
common/lib/capa/capa/responsetypes.py
+13
-5
No files found.
common/lib/capa/capa/responsetypes.py
View file @
81c4e4f7
...
...
@@ -927,15 +927,19 @@ class CustomResponse(LoncapaResponse):
# actual function that will re-execute the original script,
# and invoke the function with the data needed.
def
make_check_function
(
script_code
,
cfn
):
def
check_function
(
expect
,
ans
):
code
=
(
script_code
+
"
\n
"
+
"cfn_return =
%
s(expect, ans)
\n
"
%
cfn
)
def
check_function
(
expect
,
ans
,
**
kwargs
):
code
=
[
script_code
,
"kwargs = {}"
]
for
name
,
val
in
kwargs
.
iteritems
():
if
isinstance
(
val
,
(
str
,
list
,
tuple
,
int
,
long
,
float
,
dict
)):
code
.
append
(
"kwargs[
%
r] =
%
r"
%
(
name
,
val
))
code
.
append
(
"cfn_return =
%
s(expect, ans, **kwargs)"
%
cfn
)
code
.
append
(
""
)
# a final newline
globals_dict
=
{
'expect'
:
expect
,
'ans'
:
ans
,
}
locals_dict
=
{}
safe_exec
.
safe_exec
(
code
,
globals_dict
,
locals_dict
)
safe_exec
.
safe_exec
(
"
\n
"
.
join
(
code
)
,
globals_dict
,
locals_dict
)
return
locals_dict
[
'cfn_return'
]
return
check_function
...
...
@@ -954,6 +958,8 @@ class CustomResponse(LoncapaResponse):
else
:
self
.
code
=
answer
.
text
self
.
cfn_kwargs_keys
=
[]
def
get_score
(
self
,
student_answers
):
'''
student_answers is a dict with everything from request.POST, but with the first part
...
...
@@ -1054,7 +1060,8 @@ class CustomResponse(LoncapaResponse):
log
.
debug
(
" submission =
%
s"
%
submission
)
try
:
answer_given
=
submission
[
0
]
if
(
len
(
idset
)
==
1
)
else
submission
ret
=
fn
(
self
.
expect
,
answer_given
)
kwargs
=
{
n
:
self
.
context
.
get
(
n
)
for
n
in
self
.
cfn_kwargs_keys
}
ret
=
fn
(
self
.
expect
,
answer_given
,
**
kwargs
)
except
Exception
as
err
:
self
.
_handle_exec_exception
(
err
)
...
...
@@ -1203,6 +1210,7 @@ class SymbolicResponse(CustomResponse):
self
.
context
[
'script_code'
]
+=
"from symmath import symmath_check
\n
"
self
.
xml
.
set
(
'cfn'
,
'symmath_check'
)
CustomResponse
.
setup_response
(
self
)
self
.
cfn_kwargs_keys
.
extend
([
'dynamath'
,
'options'
,
'debug'
])
#-----------------------------------------------------------------------------
...
...
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