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
37896ac5
Commit
37896ac5
authored
Dec 26, 2011
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Gradual move to XPath/XQuery initiated
parent
20db8e6f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
26 deletions
+61
-26
courseware/capa_module.py
+35
-20
courseware/capa_problem.py
+1
-1
courseware/content_parser.py
+9
-0
courseware/static/js/video_player.js
+16
-5
No files found.
courseware/capa_module.py
View file @
37896ac5
...
...
@@ -7,7 +7,10 @@ from django.http import Http404
import
dateutil
import
datetime
from
xml.dom.minidom
import
parse
,
parseString
#from xml.dom.minidom import parse, parseString
import
content_parser
import
libxml2
## TODO: Abstract out from Django
from
django.conf
import
settings
...
...
@@ -65,7 +68,8 @@ class LoncapaModule(XModule):
# User submitted a problem, and hasn't reset. We don't want
# more submissions.
if
self
.
lcp
.
done
:
if
self
.
lcp
.
done
and
not
self
.
rerandomize
:
#print "!"
check_button
=
False
save_button
=
False
...
...
@@ -85,6 +89,7 @@ class LoncapaModule(XModule):
'save_button'
:
save_button
,
'answer_available'
:
self
.
answer_available
(),
'ajax_url'
:
self
.
ajax_url
,
'attempts'
:
attempts_str
})
if
encapsulate
:
html
=
'<div id="main_{id}">'
.
format
(
id
=
self
.
item_id
)
+
html
+
"</div>"
...
...
@@ -98,43 +103,53 @@ class LoncapaModule(XModule):
self
.
max_attempts
=
None
self
.
due_date
=
None
dom
=
parseString
(
xml
)
node
=
dom
.
childNodes
[
0
]
#dom=parseString(xml)
dom2
=
libxml2
.
parseMemory
(
xml
,
len
(
xml
))
#node=dom.childNodes[0]
self
.
due_date
=
node
.
getAttribute
(
"due"
)
#self.due_date=node.getAttribute("due")
self
.
due_date
=
content_parser
.
item
(
dom2
.
xpathEval
(
'/problem/@due'
))
if
len
(
self
.
due_date
)
>
0
:
self
.
due_date
=
dateutil
.
parser
.
parse
(
self
.
due_date
)
else
:
self
.
due_date
=
None
self
.
max_attempts
=
node
.
getAttribute
(
"attempts"
)
#self.max_attempts=node.getAttribute("attempts")
self
.
max_attempts
=
content_parser
.
item
(
dom2
.
xpathEval
(
'/problem/@attempts'
))
if
len
(
self
.
max_attempts
)
>
0
:
self
.
max_attempts
=
int
(
self
.
max_attempts
)
else
:
self
.
max_attempts
=
None
self
.
show_answer
=
node
.
getAttribute
(
"showanswer"
)
#self.show_answer=node.getAttribute("showanswer")
self
.
show_answer
=
content_parser
.
item
(
dom2
.
xpathEval
(
'/problem/@showanswer'
))
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
self
.
rerandomize
=
content_parser
.
item
(
dom2
.
xpathEval
(
'/problem/@rerandomize'
))
#self.rerandomize=node.getAttribute("rerandomize")
if
self
.
rerandomize
==
""
:
self
.
rerandomize
=
True
elif
self
.
rerandomize
==
"false"
:
self
.
rerandomize
=
False
elif
self
.
rerandomize
==
"true"
:
self
.
rerandomize
=
True
else
:
raise
Exception
(
"Invalid re
settable attribute "
+
self
.
resettabl
e
)
raise
Exception
(
"Invalid re
randomize attribute "
+
self
.
rerandomiz
e
)
if
state
!=
None
:
state
=
json
.
loads
(
state
)
if
state
!=
None
and
'attempts'
in
state
:
self
.
attempts
=
state
[
'attempts'
]
self
.
filename
=
node
.
getAttribute
(
"filename"
)
self
.
filename
=
content_parser
.
item
(
dom2
.
xpathEval
(
'/problem/@filename'
))
#self.filename=node.getAttribute("filename")
#print self.filename
filename
=
settings
.
DATA_DIR
+
"problems/"
+
self
.
filename
+
".xml"
self
.
name
=
node
.
getAttribute
(
"name"
)
#self.name=node.getAttribute("name")
self
.
name
=
content_parser
.
item
(
dom2
.
xpathEval
(
'/problem/@name'
))
self
.
lcp
=
LoncapaProblem
(
filename
,
self
.
item_id
,
state
)
def
handle_ajax
(
self
,
dispatch
,
get
):
...
...
@@ -209,7 +224,7 @@ class LoncapaModule(XModule):
# Problem submitted. Student should reset before checking
# again.
if
self
.
lcp
.
done
and
self
.
re
settabl
e
:
if
self
.
lcp
.
done
and
self
.
re
randomiz
e
:
print
"cpdr"
raise
Http404
...
...
@@ -232,7 +247,7 @@ class LoncapaModule(XModule):
# Problem submitted. Student should reset before saving
# again.
if
self
.
lcp
.
done
and
self
.
re
settabl
e
:
if
self
.
lcp
.
done
and
self
.
re
randomiz
e
:
print
"spdr"
return
"Problem needs to be reset prior to save."
...
...
@@ -257,7 +272,7 @@ class LoncapaModule(XModule):
self
.
lcp
.
answers
=
dict
()
self
.
lcp
.
correct_map
=
dict
()
if
self
.
re
settabl
e
:
if
self
.
re
randomiz
e
:
self
.
lcp
.
context
=
dict
()
self
.
lcp
.
questions
=
dict
()
# Detailed info about questions in problem instance. TODO: Should be by id and not lid.
self
.
lcp
.
seed
=
None
...
...
courseware/capa_problem.py
View file @
37896ac5
...
...
@@ -90,7 +90,7 @@ class LoncapaProblem():
ot
=
False
## Are we in an outtext context?
print
"Here"
,
dom
#
print "Here", dom
# Loop through the nodes of the problem, and
for
e
in
dom
.
childNodes
:
...
...
courseware/content_parser.py
View file @
37896ac5
...
...
@@ -9,6 +9,15 @@ course XML file and the rest of the system.
TODO: Shift everything from xml.dom.minidom to XPath (or XQuery)
'''
def
item
(
l
,
default
=
""
,
process
=
lambda
x
:
x
):
if
len
(
l
)
==
0
:
return
default
elif
len
(
l
)
==
1
:
return
process
(
l
[
0
]
.
getContent
())
else
:
raise
Exception
(
'Malformed XML'
)
def
course_file
(
user
):
# TODO: Cache. Also, return the libxml2 object.
return
settings
.
DATA_DIR
+
UserProfile
.
objects
.
get
(
user
=
user
)
.
courseware
...
...
courseware/static/js/video_player.js
View file @
37896ac5
...
...
@@ -125,15 +125,26 @@ function videoDestroy() {
ytplayer
=
false
;
}
function
log_event
(
e
)
{
function
log_event
(
e
,
d
)
{
// CRITICAL TODO: Change to AJAX
//$("#eventlog").append("<br>");
//$("#eventlog").append(JSON.stringify(e));
window
[
'console'
].
log
(
JSON
.
stringify
(
e
));
// TODO: Figure out
// XMLHttpRequest cannot load http://localhost:7000/userlog. Origin http://localhost:8000 is not allowed by Access-Control-Allow-Origin.
/*window['console'].log(JSON.stringify(e));
$.get("http://localhost:7000/userlog",
{'user':'pmitros',
'key':'key',
'event_type':'unknown',
'data':'e'},
function(data) {
});*/
}
function
seek_slide
(
type
,
oe
,
value
)
{
//log_event([type, value]);
//log_event(
'video',
[type, value]);
if
(
type
==
'slide'
)
{
// HACK/TODO: Youtube recommends this be false for slide and true for stop.
// Works better on my system with true/true.
...
...
@@ -145,7 +156,7 @@ function seek_slide(type,oe,value) {
ytplayer
.
seekTo
(
value
,
true
);
}
else
if
(
type
==
'stop'
)
{
ytplayer
.
seekTo
(
value
,
true
);
log_event
([
type
,
value
]);
log_event
(
'video'
,
[
type
,
value
]);
}
update_captions
(
value
);
...
...
@@ -166,7 +177,7 @@ function get_state() {
function
onytplayerStateChange
(
newState
)
{
setytplayerState
(
newState
);
log_event
([
'State Change'
,
newState
,
get_state
()]);
log_event
(
'video'
,
[
'State Change'
,
newState
,
get_state
()]);
}
function
onPlayerError
(
errorCode
)
{
...
...
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