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
86217379
Commit
86217379
authored
Sep 15, 2012
by
David Ormsbee
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #700 from MITx/kimth/H1P1-debug
Reset CapaProblem when state HTML is corrupt
parents
f1349eea
7682663e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
7 deletions
+65
-7
common/lib/xmodule/xmodule/capa_module.py
+49
-7
common/lib/xmodule/xmodule/css/capa/display.scss
+16
-0
No files found.
common/lib/xmodule/xmodule/capa_module.py
View file @
86217379
import
cgi
import
datetime
import
dateutil
import
dateutil.parser
...
...
@@ -131,17 +132,17 @@ class CapaModule(XModule):
self
.
weight
=
None
if
self
.
rerandomize
==
'never'
:
seed
=
1
se
lf
.
se
ed
=
1
elif
self
.
rerandomize
==
"per_student"
and
hasattr
(
self
.
system
,
'id'
):
seed
=
system
.
id
se
lf
.
se
ed
=
system
.
id
else
:
seed
=
None
se
lf
.
se
ed
=
None
try
:
# TODO (vshnayder): move as much as possible of this work and error
# checking to descriptor load time
self
.
lcp
=
LoncapaProblem
(
self
.
definition
[
'data'
],
self
.
location
.
html_id
(),
instance_state
,
seed
=
seed
,
system
=
self
.
system
)
instance_state
,
seed
=
se
lf
.
se
ed
,
system
=
self
.
system
)
except
Exception
as
err
:
msg
=
'cannot create LoncapaProblem {loc}: {err}'
.
format
(
loc
=
self
.
location
.
url
(),
err
=
err
)
...
...
@@ -160,7 +161,7 @@ class CapaModule(XModule):
(
self
.
location
.
url
(),
msg
))
self
.
lcp
=
LoncapaProblem
(
problem_text
,
self
.
location
.
html_id
(),
instance_state
,
seed
=
seed
,
system
=
self
.
system
)
instance_state
,
seed
=
se
lf
.
se
ed
,
system
=
self
.
system
)
else
:
# add extra info and raise
raise
Exception
(
msg
),
None
,
sys
.
exc_info
()[
2
]
...
...
@@ -220,9 +221,10 @@ class CapaModule(XModule):
try
:
html
=
self
.
lcp
.
get_html
()
except
Exception
,
err
:
log
.
exception
(
err
)
# TODO (vshnayder): another switch on DEBUG.
if
self
.
system
.
DEBUG
:
log
.
exception
(
err
)
msg
=
(
'[courseware.capa.capa_module] <font size="+1" color="red">'
'Failed to generate HTML for problem
%
s</font>'
%
...
...
@@ -231,7 +233,47 @@ class CapaModule(XModule):
msg
+=
'<p><pre>
%
s</pre></p>'
%
traceback
.
format_exc
()
.
replace
(
'<'
,
'<'
)
html
=
msg
else
:
raise
# We're in non-debug mode, and possibly even in production. We want
# to avoid bricking of problem as much as possible
# Presumably, student submission has corrupted LoncapaProblem HTML.
# First, pull down all student answers
student_answers
=
self
.
lcp
.
student_answers
answer_ids
=
student_answers
.
keys
()
# Some inputtypes, such as dynamath, have additional "hidden" state that
# is not exposed to the student. Keep those hidden
# TODO: Use regex, e.g. 'dynamath' is suffix at end of answer_id
hidden_state_keywords
=
[
'dynamath'
]
for
answer_id
in
answer_ids
:
for
hidden_state_keyword
in
hidden_state_keywords
:
if
answer_id
.
find
(
hidden_state_keyword
)
>=
0
:
student_answers
.
pop
(
answer_id
)
# Next, generate a fresh LoncapaProblem
self
.
lcp
=
LoncapaProblem
(
self
.
definition
[
'data'
],
self
.
location
.
html_id
(),
state
=
None
,
# Tabula rasa
seed
=
self
.
seed
,
system
=
self
.
system
)
# Prepend a scary warning to the student
warning
=
'<div class="capa_reset">'
\
'<h2>Warning: The problem has been reset to its initial state!</h2>'
\
'The problem
\'
s state was corrupted by an invalid submission. '
\
'The submission consisted of:'
\
'<ul>'
for
student_answer
in
student_answers
.
values
():
if
student_answer
!=
''
:
warning
+=
'<li>'
+
cgi
.
escape
(
student_answer
)
+
'</li>'
warning
+=
'</ul>'
\
'If this error persists, please contact the course staff.'
\
'</div>'
html
=
warning
try
:
html
+=
self
.
lcp
.
get_html
()
except
Exception
,
err
:
# Couldn't do it. Give up
log
.
exception
(
err
)
raise
content
=
{
'name'
:
self
.
display_name
,
'html'
:
html
,
...
...
common/lib/xmodule/xmodule/css/capa/display.scss
View file @
86217379
...
...
@@ -465,6 +465,22 @@ section.problem {
margin-top
:
10px
;
}
div
.capa_reset
{
padding
:
25px
;
border
:
1px
solid
$error-red
;
background-color
:
lighten
(
$error-red
,
25%
);
border-radius
:
3px
;
font-size
:
1em
;
margin-top
:
10px
;
margin-bottom
:
10px
;
}
.capa_reset
>
h2
{
color
:
#AA0000
;
}
.capa_reset
li
{
font-size
:
0
.9em
;
}
.hints
{
border
:
1px
solid
#ccc
;
...
...
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