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
10e3d8b9
Commit
10e3d8b9
authored
Dec 25, 2011
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show answer appears to work
parent
b973f358
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
14 deletions
+39
-14
courseware/capa_module.py
+31
-12
courseware/capa_problem.py
+8
-2
No files found.
courseware/capa_module.py
View file @
10e3d8b9
...
...
@@ -5,6 +5,7 @@ import random, numpy, math, scipy, sys, StringIO, os, struct, json
from
x_module
import
XModule
from
capa_problem
import
LoncapaProblem
from
django.http
import
Http404
import
dateutil
import
datetime
...
...
@@ -81,6 +82,7 @@ class LoncapaModule(XModule):
'id'
:
self
.
filename
,
'check_button'
:
check_button
,
'save_button'
:
save_button
,
'answer_available'
:
self
.
answer_available
(),
'ajax_url'
:
self
.
ajax_url
,
})
if
encapsulate
:
...
...
@@ -114,6 +116,16 @@ class LoncapaModule(XModule):
if
self
.
show_answer
==
""
:
self
.
show_answer
=
"closed"
self
.
resettable
=
node
.
getAttribute
(
"resettable"
)
if
self
.
resettable
==
""
:
self
.
resettable
=
True
elif
self
.
resettable
==
"false"
:
self
.
resettable
=
False
elif
self
.
resettable
==
"true"
:
self
.
resettable
=
True
else
:
raise
Exception
(
"Invalid resettable attribute "
+
self
.
resettable
)
if
state
!=
None
:
state
=
json
.
loads
(
state
)
if
state
!=
None
and
'attempts'
in
state
:
...
...
@@ -135,12 +147,22 @@ class LoncapaModule(XModule):
response
=
self
.
reset_problem
(
get
)
elif
dispatch
==
'problem_save'
:
response
=
self
.
save_problem
(
get
)
elif
dispatch
==
'
get_answer
'
:
elif
dispatch
==
'
problem_show
'
:
response
=
self
.
get_answer
(
get
)
else
:
return
"Error"
return
response
def
closed
(
self
):
''' Is the student still allowed to submit answers? '''
if
self
.
attempts
==
self
.
max_attempts
:
return
True
if
self
.
due_date
!=
None
and
datetime
.
datetime
.
utcnow
()
>
self
.
due_date
:
return
True
return
False
def
answer_available
(
self
):
''' Is the user allowed to see an answer?
'''
...
...
@@ -160,13 +182,14 @@ class LoncapaModule(XModule):
return
True
if
self
.
show_answer
==
'closed'
and
not
self
.
closed
():
return
False
print
"aa"
,
self
.
show_answer
raise
Http404
def
get_answer
(
self
,
get
):
if
not
self
.
answer_available
():
raise
Http404
else
:
r
aise
Http404
r
eturn
json
.
dumps
(
self
.
lcp
.
get_question_answers
())
# Figure out if we should move these to capa_problem?
...
...
@@ -178,11 +201,9 @@ class LoncapaModule(XModule):
def
check_problem
(
self
,
get
):
''' Checks whether answers to a problem are correct, and returns
a map of correct/incorrect answers '''
if
self
.
attempts
==
self
.
max_attempts
:
return
"Too many attempts. You shouldn't be here."
if
self
.
due_date
!=
None
and
datetime
.
datetime
.
utcnow
()
>
self
.
due_date
:
return
"Too late. problem was due."
if
self
.
closed
():
print
"cp"
raise
Http404
self
.
attempts
=
self
.
attempts
+
1
self
.
lcp
.
done
=
True
...
...
@@ -196,11 +217,9 @@ class LoncapaModule(XModule):
return
js
def
save_problem
(
self
,
get
):
if
self
.
attempts
==
self
.
max_attempts
:
return
"Too many attempts. You shouldn't be here."
if
self
.
due_date
!=
None
and
datetime
.
datetime
.
utcnow
()
>
self
.
due_date
:
return
"Too late. problem was due."
if
self
.
closed
():
print
"sp"
raise
Http404
answers
=
dict
()
for
key
in
get
:
...
...
courseware/capa_problem.py
View file @
10e3d8b9
...
...
@@ -121,6 +121,12 @@ class LoncapaProblem():
def
set_answers
(
self
,
answers
):
self
.
answers
=
answers
def
get_question_answers
(
self
):
rv
=
dict
()
for
key
in
self
.
questions
:
rv
[
key
]
=
str
(
self
.
questions
[
key
][
'answer'
])
return
rv
def
grade_answers
(
self
,
answers
):
''' Takes a map of IDs to answers. Return which ones are correct '''
self
.
answers
=
answers
...
...
@@ -189,7 +195,7 @@ class LoncapaProblem():
if
id
in
self
.
correct_map
and
self
.
correct_map
[
id
]
==
'incorrect'
:
icon
=
'close'
html
=
'<input type="text" name="input_{id}" id="input_{id}" value="{value}"><span class="ui-icon ui-icon-{icon}" style="display:inline-block;" id="status_{id}"></span> '
.
format
(
id
=
id
,
value
=
value
,
icon
=
icon
)
html
=
'<input type="text" name="input_{id}" id="input_{id}" value="{value}"><span
id="answer_{id}"></span><span
class="ui-icon ui-icon-{icon}" style="display:inline-block;" id="status_{id}"></span> '
.
format
(
id
=
id
,
value
=
value
,
icon
=
icon
)
return
html
def
grade_fr
(
self
,
question
,
answer
):
...
...
@@ -245,7 +251,7 @@ class LoncapaProblem():
if
id
in
self
.
correct_map
and
self
.
correct_map
[
id
]
==
'incorrect'
:
icon
=
'close'
html
=
'<input type="text" name="input_{id}" id="input_{id}" value="{value}"><span class="ui-icon ui-icon-{icon}" style="display:inline-block;" id="status_{id}"></span> '
.
format
(
id
=
id
,
value
=
value
,
icon
=
icon
)
html
=
'<input type="text" name="input_{id}" id="input_{id}" value="{value}"><span
id="answer_{id}"></span><span
class="ui-icon ui-icon-{icon}" style="display:inline-block;" id="status_{id}"></span> '
.
format
(
id
=
id
,
value
=
value
,
icon
=
icon
)
return
html
graders
=
{
'numericalresponse'
:
grade_nr
,
...
...
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