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
4d3e410b
Commit
4d3e410b
authored
Jul 02, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make mapping from xml attributes to metadata values less manual
parent
94af3ce8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
10 deletions
+16
-10
common/lib/xmodule/xmodule/xml_module.py
+16
-10
No files found.
common/lib/xmodule/xmodule/xml_module.py
View file @
4d3e410b
...
@@ -71,6 +71,13 @@ class XmlDescriptor(XModuleDescriptor):
...
@@ -71,6 +71,13 @@ class XmlDescriptor(XModuleDescriptor):
metadata_attributes
=
(
'format'
,
'graceperiod'
,
'showanswer'
,
'rerandomize'
,
metadata_attributes
=
(
'format'
,
'graceperiod'
,
'showanswer'
,
'rerandomize'
,
'due'
,
'graded'
,
'name'
,
'slug'
)
'due'
,
'graded'
,
'name'
,
'slug'
)
# A dictionary mapping xml attribute names to function of the value
# that return the metadata key and value
xml_attribute_map
=
{
'graded'
:
lambda
val
:
(
'graded'
,
val
==
'true'
),
'name'
:
lambda
val
:
(
'display_name'
,
val
),
}
@classmethod
@classmethod
def
definition_from_xml
(
cls
,
xml_object
,
system
):
def
definition_from_xml
(
cls
,
xml_object
,
system
):
"""
"""
...
@@ -116,16 +123,15 @@ class XmlDescriptor(XModuleDescriptor):
...
@@ -116,16 +123,15 @@ class XmlDescriptor(XModuleDescriptor):
def
metadata_loader
():
def
metadata_loader
():
metadata
=
{}
metadata
=
{}
for
attr
in
(
'format'
,
'graceperiod'
,
'showanswer'
,
'rerandomize'
,
'due'
):
for
attr
in
cls
.
metadata_attributes
:
from_xml
=
xml_object
.
get
(
attr
)
val
=
xml_object
.
get
(
attr
)
if
from_xml
is
not
None
:
if
val
is
not
None
:
metadata
[
attr
]
=
from_xml
map_fn
=
cls
.
xml_attribute_map
.
get
(
attr
)
if
map_fn
is
None
:
if
xml_object
.
get
(
'graded'
)
is
not
None
:
metadata
[
attr
]
=
val
metadata
[
'graded'
]
=
xml_object
.
get
(
'graded'
)
==
'true'
else
:
key
,
val
=
map_fn
(
val
)
if
xml_object
.
get
(
'name'
)
is
not
None
:
metadata
[
key
]
=
val
metadata
[
'display_name'
]
=
xml_object
.
get
(
'name'
)
return
metadata
return
metadata
...
...
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