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
ba2c0335
Commit
ba2c0335
authored
Jan 21, 2012
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
All modules moved into new OO framework
parent
16ab1bb5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
64 deletions
+74
-64
courseware/module_render.py
+3
-59
courseware/modules/seq_module.py
+71
-0
courseware/modules/vertical_module.py
+0
-5
No files found.
courseware/module_render.py
View file @
ba2c0335
...
...
@@ -21,6 +21,7 @@ import courseware.modules.video_module
import
courseware.modules.vertical_module
import
courseware.modules.html_module
import
courseware.modules.schematic_module
import
courseware.modules.seq_module
from
models
import
StudentModule
...
...
@@ -40,6 +41,7 @@ modx_modules={'problem':courseware.modules.capa_module.LoncapaModule,
'video'
:
courseware
.
modules
.
video_module
.
VideoModule
,
'html'
:
courseware
.
modules
.
html_module
.
HtmlModule
,
'vertical'
:
courseware
.
modules
.
vertical_module
.
VerticalModule
,
'sequential'
:
courseware
.
modules
.
seq_module
.
SequentialModule
,
'schematic'
:
courseware
.
modules
.
schematic_module
.
SchematicModule
}
def
make_track_function
(
request
):
...
...
@@ -83,52 +85,6 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
# Return whatever the module wanted to return to the client/caller
return
HttpResponse
(
ajax_return
)
def
seq_module
(
request
,
module
):
''' Layout module which lays out content in a temporal sequence
'''
def
j
(
m
):
# jsonify contents so it can be embedded in a js array
# We also need to split </script> tags so they don't break
# mid-string
if
'init_js'
not
in
m
:
m
[
'init_js'
]
=
""
if
'type'
not
in
m
:
m
[
'init_js'
]
=
""
content
=
json
.
dumps
(
m
[
'content'
])
content
=
content
.
replace
(
'</script>'
,
'<"+"/script>'
)
return
{
'content'
:
content
,
"destroy_js"
:
m
[
'destroy_js'
],
'init_js'
:
m
[
'init_js'
],
'type'
:
m
[
'type'
]}
contents
=
[(
e
.
get
(
"name"
),
j
(
render_module
(
request
,
e
)))
\
for
e
in
module
]
js
=
""
iid
=
uuid
.
uuid1
()
.
hex
params
=
{
'items'
:
contents
,
'id'
:
"seq"
}
# TODO/BUG: Destroy JavaScript should only be called for the active view
# This calls it for all the views
#
# To fix this, we'd probably want to have some way of assigning unique
# IDs to sequences.
destroy_js
=
""
.
join
([
e
[
1
][
'destroy_js'
]
for
e
in
contents
if
'destroy_js'
in
e
[
1
]])
if
module
.
tag
==
'sequential'
:
return
{
'init_js'
:
js
+
render_to_string
(
'seq_module.js'
,
params
),
"destroy_js"
:
destroy_js
,
'content'
:
render_to_string
(
'seq_module.html'
,
params
),
'type'
:
'sequential'
}
if
module
.
tag
==
'tab'
:
params
[
'id'
]
=
'tab'
return
{
'init_js'
:
js
+
render_to_string
(
'tab_module.js'
,
params
),
"destroy_js"
:
destroy_js
,
'content'
:
render_to_string
(
'tab_module.html'
,
params
),
'type'
:
'tab'
}
def
render_x_module
(
request
,
xml_module
):
''' Generic module for extensions. This renders to HTML. '''
# Check if problem has an instance in DB
...
...
@@ -172,20 +128,8 @@ def render_x_module(request, xml_module):
return
content
module_types
=
{
'video'
:
render_x_module
,
'html'
:
render_x_module
,
'tab'
:
seq_module
,
'vertical'
:
render_x_module
,
'sequential'
:
seq_module
,
'problem'
:
render_x_module
,
'schematic'
:
render_x_module
}
def
render_module
(
request
,
module
):
''' Generic dispatch for internal modules. '''
if
module
==
None
:
return
{
"content"
:
""
}
if
str
(
module
.
tag
)
in
module_types
:
return
module_types
[
module
.
tag
](
request
,
module
)
print
"rm404"
raise
Http404
return
render_x_module
(
request
,
module
)
courseware/modules/seq_module.py
0 → 100644
View file @
ba2c0335
from
x_module
import
XModule
from
lxml
import
etree
import
json
## TODO: Abstract out from Django
from
django.conf
import
settings
from
djangomako.shortcuts
import
render_to_response
,
render_to_string
class
SequentialModule
(
XModule
):
''' Layout module which lays out content in a temporal sequence
'''
id_attribute
=
'id'
def
get_state
(
self
):
return
json
.
dumps
({
})
def
get_xml_tags
():
return
[
"sequential"
,
'tab'
]
def
get_html
(
self
):
return
self
.
content
def
get_init_js
(
self
):
return
self
.
init_js
def
get_destroy_js
(
self
):
return
self
.
destroy_js
def
__init__
(
self
,
xml
,
item_id
,
ajax_url
=
None
,
track_url
=
None
,
state
=
None
,
track_function
=
None
,
render_function
=
None
,
meta
=
None
):
XModule
.
__init__
(
self
,
xml
,
item_id
,
ajax_url
,
track_url
,
state
,
track_function
,
render_function
)
xmltree
=
etree
.
fromstring
(
xml
)
def
j
(
m
):
''' jsonify contents so it can be embedded in a js array
We also need to split </script> tags so they don't break
mid-string'''
if
'init_js'
not
in
m
:
m
[
'init_js'
]
=
""
if
'type'
not
in
m
:
m
[
'init_js'
]
=
""
content
=
json
.
dumps
(
m
[
'content'
])
content
=
content
.
replace
(
'</script>'
,
'<"+"/script>'
)
return
{
'content'
:
content
,
"destroy_js"
:
m
[
'destroy_js'
],
'init_js'
:
m
[
'init_js'
],
'type'
:
m
[
'type'
]}
contents
=
[(
e
.
get
(
"name"
),
j
(
render_function
(
meta
,
e
)))
\
for
e
in
xmltree
]
js
=
""
params
=
{
'items'
:
contents
,
'id'
:
"seq"
}
# TODO/BUG: Destroy JavaScript should only be called for the active view
# This calls it for all the views
#
# To fix this, we'd probably want to have some way of assigning unique
# IDs to sequences.
destroy_js
=
""
.
join
([
e
[
1
][
'destroy_js'
]
for
e
in
contents
if
'destroy_js'
in
e
[
1
]])
if
xmltree
.
tag
==
'sequential'
:
self
.
init_js
=
js
+
render_to_string
(
'seq_module.js'
,
params
)
self
.
destroy_js
=
destroy_js
self
.
content
=
render_to_string
(
'seq_module.html'
,
params
)
if
xmltree
.
tag
==
'tab'
:
params
[
'id'
]
=
'tab'
self
.
init_js
=
js
+
render_to_string
(
'tab_module.js'
,
params
)
self
.
destroy_js
=
destroy_js
self
.
content
=
render_to_string
(
'tab_module.html'
,
params
)
courseware/modules/vertical_module.py
View file @
ba2c0335
...
...
@@ -28,11 +28,6 @@ class VerticalModule(XModule):
def
__init__
(
self
,
xml
,
item_id
,
ajax_url
=
None
,
track_url
=
None
,
state
=
None
,
track_function
=
None
,
render_function
=
None
,
meta
=
None
):
XModule
.
__init__
(
self
,
xml
,
item_id
,
ajax_url
,
track_url
,
state
,
track_function
,
render_function
)
xmltree
=
etree
.
fromstring
(
xml
)
self
.
filename
=
None
filename_l
=
xmltree
.
xpath
(
"/html/@filename"
)
if
len
(
filename_l
)
>
0
:
self
.
filename
=
str
(
filename_l
[
0
])
self
.
contents
=
[(
e
.
get
(
"name"
),
self
.
render_function
(
meta
,
e
))
\
for
e
in
xmltree
]
self
.
init_js_text
=
""
.
join
([
e
[
1
][
'init_js'
]
for
e
in
self
.
contents
if
'init_js'
in
e
[
1
]])
...
...
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