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
a94e4d2f
Commit
a94e4d2f
authored
Jun 29, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rearrange x_module definition into sections
parent
c6d5eea8
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
37 deletions
+53
-37
common/lib/xmodule/x_module.py
+53
-37
No files found.
common/lib/xmodule/x_module.py
View file @
a94e4d2f
...
...
@@ -213,6 +213,7 @@ class XModuleDescriptor(Plugin):
# A list of metadata that this module can inherit from its parent module
inheritable_metadata
=
(
'graded'
,
'due'
,
'graceperiod'
,
'showanswer'
,
'rerandomize'
)
# ============================= STRUCTURAL MANIPULATION ===========================
def
__init__
(
self
,
system
,
definition
=
None
,
...
...
@@ -253,6 +254,43 @@ class XModuleDescriptor(Plugin):
self
.
_child_instances
=
None
def
inherit_metadata
(
self
,
metadata
):
"""
Updates this module with metadata inherited from a containing module.
Only metadata specified in self.inheritable_metadata will
be inherited
"""
# Set all inheritable metadata from kwargs that are
# in self.inheritable_metadata and aren't already set in metadata
for
attr
in
self
.
inheritable_metadata
:
if
attr
not
in
self
.
metadata
and
attr
in
metadata
:
self
.
metadata
[
attr
]
=
metadata
[
attr
]
def
get_children
(
self
):
"""Returns a list of XModuleDescriptor instances for the children of this module"""
if
self
.
_child_instances
is
None
:
self
.
_child_instances
=
[]
for
child_loc
in
self
.
definition
.
get
(
'children'
,
[]):
child
=
self
.
system
.
load_item
(
child_loc
)
child
.
inherit_metadata
(
self
.
metadata
)
self
.
_child_instances
.
append
(
child
)
return
self
.
_child_instances
def
xmodule_constructor
(
self
,
system
):
"""
Returns a constructor for an XModule. This constructor takes two arguments:
instance_state and shared_state, and returns a fully nstantiated XModule
"""
return
partial
(
self
.
module_class
,
system
,
self
.
location
,
self
.
definition
,
metadata
=
self
.
metadata
)
# ================================= JSON PARSING ===================================
@staticmethod
def
load_from_json
(
json_data
,
system
,
default_class
=
None
):
"""
...
...
@@ -280,6 +318,7 @@ class XModuleDescriptor(Plugin):
"""
return
cls
(
system
=
system
,
**
json_data
)
# ================================= XML PARSING ====================================
@staticmethod
def
load_from_xml
(
xml_data
,
system
,
...
...
@@ -315,6 +354,20 @@ class XModuleDescriptor(Plugin):
"""
raise
NotImplementedError
(
'Modules must implement from_xml to be parsable from xml'
)
def
export_to_xml
(
self
,
resource_fs
):
"""
Returns an xml string representing this module, and all modules underneath it.
May also write required resources out to resource_fs
Assumes that modules have single parantage (that no module appears twice in the same course),
and that it is thus safe to nest modules as xml children as appropriate.
The returned XML should be able to be parsed back into an identical XModuleDescriptor
using the from_xml method with the same system, org, and course
"""
raise
NotImplementedError
(
'Modules must implement export_to_xml to enable xml export'
)
# ================================== HTML INTERFACE DEFINITIONS ======================
@classmethod
def
get_javascript
(
cls
):
"""
...
...
@@ -334,49 +387,12 @@ class XModuleDescriptor(Plugin):
"""
return
self
.
js_module
def
inherit_metadata
(
self
,
metadata
):
"""
Updates this module with metadata inherited from a containing module.
Only metadata specified in self.inheritable_metadata will
be inherited
"""
# Set all inheritable metadata from kwargs that are
# in self.inheritable_metadata and aren't already set in metadata
for
attr
in
self
.
inheritable_metadata
:
if
attr
not
in
self
.
metadata
and
attr
in
metadata
:
self
.
metadata
[
attr
]
=
metadata
[
attr
]
def
get_children
(
self
):
"""Returns a list of XModuleDescriptor instances for the children of this module"""
if
self
.
_child_instances
is
None
:
self
.
_child_instances
=
[]
for
child_loc
in
self
.
definition
.
get
(
'children'
,
[]):
child
=
self
.
system
.
load_item
(
child_loc
)
child
.
inherit_metadata
(
self
.
metadata
)
self
.
_child_instances
.
append
(
child
)
return
self
.
_child_instances
def
get_html
(
self
):
"""
Return the html used to edit this module
"""
raise
NotImplementedError
(
"get_html() must be provided by specific modules"
)
def
xmodule_constructor
(
self
,
system
):
"""
Returns a constructor for an XModule. This constructor takes two arguments:
instance_state and shared_state, and returns a fully nstantiated XModule
"""
return
partial
(
self
.
module_class
,
system
,
self
.
location
,
self
.
definition
,
metadata
=
self
.
metadata
)
class
DescriptorSystem
(
object
):
def
__init__
(
self
,
load_item
,
resources_fs
):
...
...
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