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
e83fb3f8
Commit
e83fb3f8
authored
Sep 20, 2012
by
Bridger Maxwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added new API to xmodule(descriptor). get_children_locations and has_dynamic_children.
parent
70818f8b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
5 deletions
+34
-5
common/lib/xmodule/xmodule/abtest_module.py
+6
-4
common/lib/xmodule/xmodule/x_module.py
+28
-1
No files found.
common/lib/xmodule/xmodule/abtest_module.py
View file @
e83fb3f8
...
@@ -48,10 +48,8 @@ class ABTestModule(XModule):
...
@@ -48,10 +48,8 @@ class ABTestModule(XModule):
def
get_shared_state
(
self
):
def
get_shared_state
(
self
):
return
json
.
dumps
({
'group'
:
self
.
group
})
return
json
.
dumps
({
'group'
:
self
.
group
})
def
displayable_items
(
self
):
def
get_children_locations
(
self
):
child_locations
=
self
.
definition
[
'data'
][
'group_content'
][
self
.
group
]
return
self
.
definition
[
'data'
][
'group_content'
][
self
.
group
]
children
=
[
self
.
system
.
get_module
(
loc
)
for
loc
in
child_locations
]
return
[
c
for
c
in
children
if
c
is
not
None
]
# TODO (cpennington): Use Groups should be a first class object, rather than being
# TODO (cpennington): Use Groups should be a first class object, rather than being
...
@@ -158,3 +156,7 @@ class ABTestDescriptor(RawDescriptor, XmlDescriptor):
...
@@ -158,3 +156,7 @@ class ABTestDescriptor(RawDescriptor, XmlDescriptor):
group_elem
.
append
(
etree
.
fromstring
(
child
.
export_to_xml
(
resource_fs
)))
group_elem
.
append
(
etree
.
fromstring
(
child
.
export_to_xml
(
resource_fs
)))
return
xml_object
return
xml_object
def
has_dynamic_children
(
self
):
return
True
common/lib/xmodule/xmodule/x_module.py
View file @
e83fb3f8
...
@@ -219,7 +219,7 @@ class XModule(HTMLSnippet):
...
@@ -219,7 +219,7 @@ class XModule(HTMLSnippet):
Return module instances for all the children of this module.
Return module instances for all the children of this module.
'''
'''
if
self
.
_loaded_children
is
None
:
if
self
.
_loaded_children
is
None
:
child_locations
=
self
.
definition
.
get
(
'children'
,
[]
)
child_locations
=
self
.
get_children_locations
(
)
children
=
[
self
.
system
.
get_module
(
loc
)
for
loc
in
child_locations
]
children
=
[
self
.
system
.
get_module
(
loc
)
for
loc
in
child_locations
]
# get_module returns None if the current user doesn't have access
# get_module returns None if the current user doesn't have access
# to the location.
# to the location.
...
@@ -227,6 +227,21 @@ class XModule(HTMLSnippet):
...
@@ -227,6 +227,21 @@ class XModule(HTMLSnippet):
return
self
.
_loaded_children
return
self
.
_loaded_children
def
get_children_locations
(
self
):
'''
Returns the locations of each of child modules.
Overriding this changes the behavior of get_children and
anything that uses get_children, such as get_display_items.
This method will not instantiate the modules of the children
unless absolutely necessary, so it is cheaper to call than get_children
These children will be the same children returned by the
descriptor unless descriptor.has_dynamic_children() is true.
'''
return
self
.
definition
.
get
(
'children'
,
[])
def
get_display_items
(
self
):
def
get_display_items
(
self
):
'''
'''
Returns a list of descendent module instances that will display
Returns a list of descendent module instances that will display
...
@@ -490,6 +505,18 @@ class XModuleDescriptor(Plugin, HTMLSnippet):
...
@@ -490,6 +505,18 @@ class XModuleDescriptor(Plugin, HTMLSnippet):
metadata
=
self
.
metadata
metadata
=
self
.
metadata
)
)
def
has_dynamic_children
(
self
):
"""
Returns True if this descriptor has dynamic children for a given
student when the module is created.
Returns False if the children of this descriptor are the same
children that the module will return for any student.
"""
return
False
# ================================= JSON PARSING ===========================
# ================================= JSON PARSING ===========================
@staticmethod
@staticmethod
def
load_from_json
(
json_data
,
system
,
default_class
=
None
):
def
load_from_json
(
json_data
,
system
,
default_class
=
None
):
...
...
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