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
b1b08d29
Commit
b1b08d29
authored
Jun 01, 2012
by
ichuang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
made "position" a generic parameter passed to all modules, from courseware.views.index
parent
2e2bf13e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
23 deletions
+43
-23
djangoapps/courseware/module_render.py
+29
-4
djangoapps/courseware/modules/seq_module.py
+4
-0
djangoapps/courseware/modules/x_module.py
+2
-0
djangoapps/courseware/views.py
+8
-19
No files found.
djangoapps/courseware/module_render.py
View file @
b1b08d29
...
...
@@ -38,6 +38,11 @@ class I4xSystem(object):
self
.
render_function
=
render_function
self
.
exception404
=
Http404
self
.
DEBUG
=
settings
.
DEBUG
def
get
(
self
,
attr
):
# uniform access to attributes (like etree)
return
self
.
__dict__
.
get
(
attr
)
def
set
(
self
,
attr
,
val
):
# uniform access to attributes (like etree)
self
.
__dict__
[
attr
]
=
val
def
__repr__
(
self
):
return
repr
(
self
.
__dict__
)
def
__str__
(
self
):
...
...
@@ -100,7 +105,7 @@ def get_state_from_module_object_preload(user, xml_module, module_object_preload
return
smod
,
state
def
render_x_module
(
user
,
request
,
xml_module
,
module_object_preload
):
def
render_x_module
(
user
,
request
,
xml_module
,
module_object_preload
,
position
=
None
):
''' Generic module for extensions. This renders to HTML.
modules include sequential, vertical, problem, video, html
...
...
@@ -113,6 +118,11 @@ def render_x_module(user, request, xml_module, module_object_preload):
- request : current django HTTPrequest
- xml_module : lxml etree of xml subtree for the current module
- module_object_preload : list of StudentModule objects, one of which may match this module type and id
- position : extra information from URL for user-specified position within module
Returns:
- dict which is context for HTML rendering of the specified module
'''
module_type
=
xml_module
.
tag
...
...
@@ -138,6 +148,7 @@ def render_x_module(user, request, xml_module, module_object_preload):
ajax_url
=
ajax_url
,
filestore
=
OSFS
(
data_root
),
)
system
.
set
(
'position'
,
position
)
# pass URL specified position along to module, through I4xSystem
instance
=
module_class
(
system
,
etree
.
tostring
(
xml_module
),
module_id
,
...
...
@@ -176,8 +187,22 @@ def render_x_module(user, request, xml_module, module_object_preload):
return
content
def
render_module
(
user
,
request
,
module
,
module_object_preload
):
''' Generic dispatch for internal modules. '''
def
render_module
(
user
,
request
,
module
,
module_object_preload
,
position
=
None
):
''' Generic dispatch for internal modules.
Args:
- user : django User
- request : HTTP request
- module : ElementTree (xml) for this module
- module_object_preload : list of StudentModule objects, one of which may match this module type and id
- position : extra information from URL for user-specified position within module
Returns:
- dict which is context for HTML rendering of the specified module
'''
if
module
==
None
:
return
{
"content"
:
""
}
return
render_x_module
(
user
,
request
,
module
,
module_object_preload
)
return
render_x_module
(
user
,
request
,
module
,
module_object_preload
,
position
)
djangoapps/courseware/modules/seq_module.py
View file @
b1b08d29
...
...
@@ -113,4 +113,8 @@ class Module(XModule):
state
=
json
.
loads
(
state
)
if
'position'
in
state
:
self
.
position
=
int
(
state
[
'position'
])
# if position is specified in system, then use that instead
if
system
.
get
(
'position'
):
self
.
position
=
int
(
system
.
get
(
'position'
))
self
.
rendered
=
False
djangoapps/courseware/modules/x_module.py
View file @
b1b08d29
...
...
@@ -68,6 +68,7 @@ class XModule(object):
self
.
xml
=
xml
self
.
item_id
=
item_id
self
.
state
=
state
self
.
DEBUG
=
False
if
system
:
## These are temporary; we really should go
...
...
@@ -76,4 +77,5 @@ class XModule(object):
self
.
tracker
=
system
.
track_function
self
.
filestore
=
system
.
filestore
self
.
render_function
=
system
.
render_function
self
.
DEBUG
=
system
.
DEBUG
self
.
system
=
system
djangoapps/courseware/views.py
View file @
b1b08d29
...
...
@@ -160,7 +160,11 @@ def index(request, course=None, chapter="Using the System", section="Hints",posi
- course : coursename (str)
- chapter : chapter name (str)
- section : section name (str)
- position : position in sequence, ie of <sequential> module (int)
- position : position in module, eg of <sequential> module (str)
Returns:
- HTTPresponse
'''
user
=
request
.
user
...
...
@@ -215,21 +219,6 @@ def index(request, course=None, chapter="Using the System", section="Hints",posi
else
:
module_object_preload
=
[]
if
position
and
module
and
module
.
tag
==
'sequential'
:
smod
,
state
=
get_state_from_module_object_preload
(
user
,
module
,
module_object_preload
)
newstate
=
json
.
dumps
({
'position'
:
position
})
if
smod
:
smod
.
state
=
newstate
elif
user
.
is_authenticated
():
smod
=
StudentModule
(
student
=
user
,
module_type
=
module
.
tag
,
module_id
=
module
.
get
(
'id'
),
state
=
newstate
)
smod
.
save
()
# now regenerate module_object_preload
module_object_preload
=
list
(
StudentModule
.
objects
.
filter
(
student
=
user
,
module_id__in
=
module_ids
))
context
=
{
'csrf'
:
csrf
(
request
)[
'csrf_token'
],
'accordion'
:
render_accordion
(
request
,
course
,
chapter
,
section
),
...
...
@@ -237,7 +226,7 @@ def index(request, course=None, chapter="Using the System", section="Hints",posi
}
try
:
module
=
render_module
(
user
,
request
,
module
,
module_object_preload
)
# ugh - shouldn't overload module
module
_context
=
render_module
(
user
,
request
,
module
,
module_object_preload
,
position
)
except
:
log
.
exception
(
"Unable to load module"
)
context
.
update
({
...
...
@@ -247,8 +236,8 @@ def index(request, course=None, chapter="Using the System", section="Hints",posi
return
render_to_response
(
'courseware.html'
,
context
)
context
.
update
({
'init'
:
module
.
get
(
'init_js'
,
''
),
'content'
:
module
[
'content'
],
'init'
:
module
_context
.
get
(
'init_js'
,
''
),
'content'
:
module
_context
[
'content'
],
})
result
=
render_to_response
(
'courseware.html'
,
context
)
...
...
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