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
8cf848b1
Commit
8cf848b1
authored
Jun 30, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle the filename for capa_module in the xml_module code, rather than specially in capa_module
parent
552c1997
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
27 deletions
+12
-27
common/lib/capa/capa_problem.py
+9
-13
common/lib/xmodule/capa_module.py
+3
-14
No files found.
common/lib/capa/capa_problem.py
View file @
8cf848b1
...
...
@@ -68,14 +68,13 @@ class LoncapaProblem(object):
Main class for capa Problems.
'''
def
__init__
(
self
,
fileobjec
t
,
id
,
state
=
None
,
seed
=
None
,
system
=
None
):
def
__init__
(
self
,
problem_tex
t
,
id
,
state
=
None
,
seed
=
None
,
system
=
None
):
'''
Initializes capa Problem. The problem itself is defined by the XML file
pointed to by fileobject.
Initializes capa Problem.
Arguments:
-
filesobject : an OSFS instance: see fs.osfs
-
problem_text : xml defining the problem
- id : string used as the identifier for this problem; often a filename (no spaces)
- state : student state (represented as a dict)
- seed : random number generator seed (int)
...
...
@@ -103,14 +102,11 @@ class LoncapaProblem(object):
if
not
self
.
seed
:
self
.
seed
=
struct
.
unpack
(
'i'
,
os
.
urandom
(
4
))[
0
]
self
.
fileobject
=
fileobject
# save problem file object, so we can use for debugging information later
if
getattr
(
system
,
'DEBUG'
,
False
):
# get the problem XML string from the problem file
log
.
info
(
"[courseware.capa.capa_problem.lcp.init] fileobject =
%
s"
%
fileobject
)
file_text
=
fileobject
.
read
()
file_text
=
re
.
sub
(
"startouttext
\
s*/"
,
"text"
,
file_text
)
# Convert startouttext and endouttext to proper <text></text>
file_text
=
re
.
sub
(
"endouttext
\
s*/"
,
"/text"
,
file_text
)
problem_text
=
re
.
sub
(
"startouttext
\
s*/"
,
"text"
,
problem_text
)
# Convert startouttext and endouttext to proper <text></text>
problem_text
=
re
.
sub
(
"endouttext
\
s*/"
,
"/text"
,
problem_text
)
self
.
problem_text
=
problem_text
self
.
tree
=
etree
.
XML
(
file_text
)
# parse problem XML file into an element tree
self
.
tree
=
etree
.
XML
(
problem_text
)
# parse problem XML file into an element tree
self
.
_process_includes
()
# handle any <include file="foo"> tags
# construct script processor context (eg for customresponse problems)
...
...
@@ -130,7 +126,7 @@ class LoncapaProblem(object):
self
.
done
=
False
def
__unicode__
(
self
):
return
u"LoncapaProblem ({0})"
.
format
(
self
.
fileobjec
t
)
return
u"LoncapaProblem ({0})"
.
format
(
self
.
problem_tex
t
)
def
get_state
(
self
):
''' Stored per-user session data neeeded to:
...
...
@@ -272,7 +268,7 @@ class LoncapaProblem(object):
parent
=
inc
.
getparent
()
# insert new XML into tree in place of inlcude
parent
.
insert
(
parent
.
index
(
inc
),
incxml
)
parent
.
remove
(
inc
)
log
.
debug
(
'Included
%
s into
%
s'
%
(
file
,
self
.
fileobject
))
log
.
debug
(
'Included
%
s into
%
s'
%
(
file
,
self
.
id
))
def
_extract_context
(
self
,
tree
,
seed
=
struct
.
unpack
(
'i'
,
os
.
urandom
(
4
))[
0
]):
# private
'''
...
...
common/lib/xmodule/capa_module.py
View file @
8cf848b1
...
...
@@ -117,8 +117,6 @@ class CapaModule(XModule):
if
instance_state
!=
None
and
'attempts'
in
instance_state
:
self
.
attempts
=
instance_state
[
'attempts'
]
# TODO: Should be: self.filename=only_one(dom2.xpath('/problem/@filename'))
self
.
filename
=
"problems/"
+
only_one
(
dom2
.
xpath
(
'/problem/@filename'
))
+
".xml"
self
.
name
=
only_one
(
dom2
.
xpath
(
'/problem/@name'
))
weight_string
=
only_one
(
dom2
.
xpath
(
'/problem/@weight'
))
...
...
@@ -133,20 +131,11 @@ class CapaModule(XModule):
seed
=
system
.
id
else
:
seed
=
None
try
:
fp
=
self
.
system
.
filestore
.
open
(
self
.
filename
)
except
Exception
:
log
.
exception
(
'cannot open file
%
s'
%
self
.
filename
)
if
self
.
system
.
DEBUG
:
# create a dummy problem instead of failing
fp
=
StringIO
.
StringIO
(
'<problem><text><font color="red" size="+2">Problem file
%
s is missing</font></text></problem>'
%
self
.
filename
)
fp
.
name
=
"StringIO"
else
:
raise
try
:
self
.
lcp
=
LoncapaProblem
(
fp
,
self
.
location
.
html_id
(),
instance_state
,
seed
=
seed
,
system
=
self
.
system
)
self
.
lcp
=
LoncapaProblem
(
self
.
definition
[
'data'
],
self
.
location
.
html_id
(),
instance_state
,
seed
=
seed
,
system
=
self
.
system
)
except
Exception
:
msg
=
'cannot create LoncapaProblem
%
s'
%
self
.
filename
msg
=
'cannot create LoncapaProblem
%
s'
%
self
.
url
log
.
exception
(
msg
)
if
self
.
system
.
DEBUG
:
msg
=
'<p>
%
s</p>'
%
msg
.
replace
(
'<'
,
'<'
)
...
...
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