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
9037e116
Commit
9037e116
authored
Dec 11, 2011
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X Module fully refactored
parent
a077249a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
25 deletions
+40
-25
courseware/capa_module.py
+4
-1
courseware/static/js/video_player.js
+5
-5
courseware/views.py
+24
-19
courseware/x_module.py
+7
-0
No files found.
courseware/capa_module.py
View file @
9037e116
...
...
@@ -28,7 +28,7 @@ class LoncapaModule(XModule):
return
self
.
lcp
.
get_score
()
def
max_score
(
self
):
return
len
(
lcp
.
questions
)
return
len
(
self
.
lcp
.
questions
)
def
get_html
(
self
,
encapsulate
=
True
):
html
=
self
.
lcp
.
get_html
()
...
...
@@ -40,6 +40,9 @@ class LoncapaModule(XModule):
html
=
'<div id="main_{id}">'
.
format
(
id
=
self
.
item_id
)
+
html
+
"</div>"
return
html
def
get_js
(
self
):
return
""
def
__init__
(
self
,
xml
,
item_id
,
ajax_url
=
None
,
track_url
=
None
,
state
=
None
):
XModule
.
__init__
(
self
,
xml
,
item_id
,
ajax_url
,
track_url
,
state
)
dom
=
parseString
(
xml
)
...
...
courseware/static/js/video_player.js
View file @
9037e116
...
...
@@ -71,7 +71,7 @@ function updateHTML(elmId, value) {
}
function
setytplayerState
(
newState
)
{
updateHTML
(
"playerstate"
,
newState
);
//
updateHTML("playerstate", newState);
}
function
onYouTubePlayerReady
(
playerId
)
{
...
...
@@ -143,10 +143,10 @@ function updateytplayerInfo() {
update_captions
(
getCurrentTime
());
}
updateHTML
(
"videoduration"
,
getDuration
());
updateHTML
(
"videotime"
,
getCurrentTime
());
updateHTML
(
"startbytes"
,
getStartBytes
());
updateHTML
(
"volume"
,
getVolume
());
//
updateHTML("videoduration", getDuration());
//
updateHTML("videotime", getCurrentTime());
//
updateHTML("startbytes", getStartBytes());
//
updateHTML("volume", getVolume());
}
// functions for the api calls
...
...
courseware/views.py
View file @
9037e116
...
...
@@ -17,6 +17,7 @@ from django.http import Http404
import
urllib
import
capa_module
import
video_module
from
models
import
StudentModule
...
...
@@ -55,7 +56,7 @@ def profile(request):
correct
=
response
.
grade
else
:
correct
=
0
total
=
capa_module
.
LoncapaModule
(
p
,
id
=
id
)
.
max_score
()
total
=
capa_module
.
LoncapaModule
(
p
.
toxml
(),
"id"
)
.
max_score
()
# TODO: Add state. Not useful now, but maybe someday problems will have randomized max scores?
scores
.
append
((
int
(
correct
),
total
))
score
=
{
'course'
:
course
.
getAttribute
(
'name'
),
'section'
:
s
.
getAttribute
(
"name"
),
...
...
@@ -71,7 +72,8 @@ def profile(request):
'location'
:
user_info
.
location
,
'language'
:
user_info
.
language
,
'email'
:
request
.
user
.
email
,
'homeworks'
:
hw
'homeworks'
:
hw
,
'csrf'
:
csrf
(
request
)[
'csrf_token'
]
}
return
render_to_response
(
'profile.html'
,
context
)
...
...
@@ -94,12 +96,12 @@ def render_accordion(request,course,chapter,section):
return
{
'js'
:
render_to_string
(
'accordion_init.js'
,
context
),
'content'
:
render_to_string
(
'accordion.html'
,
context
)}
def
video_mod
ule
(
request
,
module
):
def
video_mod
(
request
,
module
):
''' Shows a video, with subtitles.
'''
id
=
module
.
getAttribute
(
'youtube'
)
return
{
'js'
:
render_to_string
(
'video_init.js'
,{
'id'
:
id
}),
'content'
:
render_to_string
(
'video.html'
,{})}
'content'
:
render_to_string
(
'video.html'
,{
'id'
:
id
})}
def
html_module
(
request
,
module
):
''' Show basic text
...
...
@@ -150,33 +152,36 @@ def seq_module(request, module):
'content'
:
render_to_string
(
'seq_module.html'
,{
'items'
:
contents
})}
modx_modules
=
{
'problem'
:
capa_module
.
LoncapaModule
}
modx_modules
=
{
'problem'
:
capa_module
.
LoncapaModule
}
#, 'video1':video_module.VideoModule}
def
render_x_module
(
request
,
xml_module
):
''' Generic module for extensions. This renders to HTML. '''
# Check if problem has an instance in DB
module_id
=
xml_module
.
getAttribute
(
capa_module
.
LoncapaModule
.
id_attribute
)
module_type
=
xml_module
.
nodeName
module_class
=
modx_modules
[
module_type
]
module_id
=
xml_module
.
getAttribute
(
module_class
.
id_attribute
)
s
=
StudentModule
.
objects
.
filter
(
student
=
request
.
user
,
module_id
=
module_id
)
if
len
(
s
)
==
0
:
# If not, create one, and save it
problem
=
capa_module
.
LoncapaModule
(
xml_module
.
toxml
(),
module_id
)
instance
=
module_class
(
xml_module
.
toxml
(),
module_id
)
smod
=
StudentModule
(
student
=
request
.
user
,
module_id
=
module_id
,
state
=
problem
.
get_state
(),
xml
=
problem
.
xml
)
state
=
instance
.
get_state
(),
xml
=
instance
.
xml
)
smod
.
save
()
elif
len
(
s
)
==
1
:
# If so, render it
s
=
s
[
0
]
problem
=
capa_module
.
LoncapaModule
(
xml_module
.
toxml
(),
module_id
,
state
=
s
.
state
)
s
.
state
=
problem
.
get_state
()
instance
=
module_class
(
xml_module
.
toxml
(),
module_id
,
state
=
s
.
state
)
s
.
state
=
instance
.
get_state
()
s
.
save
()
else
:
raise
Exception
(
"Database is inconsistent (1)."
)
return
{
'content'
:
problem
.
get_html
()}
return
{
'content'
:
instance
.
get_html
(),
'js'
:
instance
.
get_js
()}
def
modx_dispatch
(
request
,
module
=
None
,
dispatch
=
None
,
id
=
None
):
''' Generic module for extensions. This handles AJAX. '''
...
...
@@ -187,14 +192,14 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
s
=
s
[
0
]
dispatch
=
dispatch
.
split
(
'?'
)[
0
]
problem
=
modx_modules
[
module
](
s
.
xml
,
s
.
module_id
,
state
=
s
.
state
)
html
=
problem
.
handle_ajax
(
dispatch
,
request
.
GET
)
s
.
state
=
problem
.
get_state
()
s
.
grade
=
problem
.
get_score
()[
'score'
]
instance
=
modx_modules
[
module
](
s
.
xml
,
s
.
module_id
,
state
=
s
.
state
)
html
=
instance
.
handle_ajax
(
dispatch
,
request
.
GET
)
s
.
state
=
instance
.
get_state
()
s
.
grade
=
instance
.
get_score
()[
'score'
]
s
.
save
()
return
HttpResponse
(
html
)
module_types
=
{
'video'
:
video_mod
ule
,
module_types
=
{
'video'
:
video_mod
,
'html'
:
html_module
,
'tab'
:
tab_module
,
'vertical'
:
vertical_module
,
...
...
courseware/x_module.py
View file @
9037e116
...
...
@@ -23,6 +23,13 @@ class XModule:
def
get_html
(
self
):
return
"Unimplemented"
def
get_js
(
self
):
''' JavaScript code to be run when problem is shown. Be aware
that this may happen several times on the same page
(e.g. student switching tabs). Common functions should be put
in the main course .js files for now. '''
return
""
def
handle_ajax
(
self
,
dispatch
,
get
):
''' dispatch is last part of the URL.
get is a dictionary-like object '''
...
...
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