Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
code.vt.edu will be down for maintenance from 0530-0630 EDT Wednesday, March 26th
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
a94e4d2f
Commit
a94e4d2f
authored
12 years ago
by
Calen Pennington
Browse files
Options
Downloads
Patches
Plain Diff
Rearrange x_module definition into sections
parent
c6d5eea8
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/lib/xmodule/x_module.py
+53
-37
53 additions, 37 deletions
common/lib/xmodule/x_module.py
with
53 additions
and
37 deletions
common/lib/xmodule/x_module.py
+
53
−
37
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
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment