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
66e47f74
Commit
66e47f74
authored
Nov 20, 2012
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a context for rendering.
parent
8d790784
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
7 deletions
+12
-7
common/lib/xmodule/xmodule/xmodule.py
+12
-7
No files found.
common/lib/xmodule/xmodule/xmodule.py
View file @
66e47f74
...
@@ -88,7 +88,7 @@ class Plugin(object):
...
@@ -88,7 +88,7 @@ class Plugin(object):
def
register_view
(
view_name
):
def
register_view
(
view_name
):
def
wrapper
(
fn
):
def
wrapper
(
fn
):
setattr
(
fn
,
'view_name'
,
view_name
)
fn
.
view_name
=
view_name
return
fn
return
fn
return
wrapper
return
wrapper
...
@@ -133,21 +133,26 @@ class XModule(Plugin):
...
@@ -133,21 +133,26 @@ class XModule(Plugin):
self
.
_view_name
=
None
self
.
_view_name
=
None
@staticmethod
@staticmethod
def
render
(
module
,
view_name
):
def
render
(
module
,
view_name
,
context
):
"""
"""
Render the specified view from the supplied module
Render the specified view from the supplied module
view_name: The string name of the view to render
module: The XModule to render
module: The XModule to render
view_name: The string name of the view to render
context: Data parent XModules make available to their children
during rendering.
"""
"""
# Make children use the appropriate render context
# Make children use the appropriate render context
try
:
try
:
module
.
_view_name
=
view_name
module
.
_view_name
=
view_name
return
module
.
find_view
(
view_name
)()
return
module
.
find_view
(
view_name
)(
context
)
finally
:
finally
:
module
.
_view_name
=
None
module
.
_view_name
=
None
def
render_child
(
self
,
child
,
view_name
=
None
):
def
render_child
(
self
,
child
,
view_name
=
None
,
context
=
None
):
"""
"""
Render a view on a child module. If view_name isn't supplied,
Render a view on a child module. If view_name isn't supplied,
render the same view on the child that is currently being rendered on the parent
render the same view on the child that is currently being rendered on the parent
...
@@ -155,11 +160,11 @@ class XModule(Plugin):
...
@@ -155,11 +160,11 @@ class XModule(Plugin):
if
view_name
is
None
:
if
view_name
is
None
:
view_name
=
self
.
_view_name
view_name
=
self
.
_view_name
return
XModule
.
render
(
child
,
view_name
)
return
XModule
.
render
(
child
,
view_name
,
context
or
{}
)
def
find_view
(
self
,
view_name
):
def
find_view
(
self
,
view_name
):
for
method_name
,
method_fn
in
inspect
.
getmembers
(
self
,
inspect
.
ismethod
):
for
method_name
,
method_fn
in
inspect
.
getmembers
(
self
,
inspect
.
ismethod
):
if
getattr
(
method_fn
,
'view_name'
,
None
)
is
not
Non
e
:
if
getattr
(
method_fn
,
'view_name'
,
None
)
==
view_nam
e
:
return
method_fn
return
method_fn
raise
MissingXModuleView
(
self
.
__class__
,
view_name
)
raise
MissingXModuleView
(
self
.
__class__
,
view_name
)
...
...
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