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
4f782aac
Commit
4f782aac
authored
Sep 03, 2012
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply attr_map translation to metadata loaded from policy file as well as from xml.
parent
80353b0a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
4 deletions
+22
-4
common/lib/xmodule/xmodule/tests/test_import.py
+4
-0
common/lib/xmodule/xmodule/xml_module.py
+16
-3
common/test/data/toy/policies/2012_Fall.json
+2
-1
No files found.
common/lib/xmodule/xmodule/tests/test_import.py
View file @
4f782aac
...
@@ -236,6 +236,10 @@ class ImportTestCase(unittest.TestCase):
...
@@ -236,6 +236,10 @@ class ImportTestCase(unittest.TestCase):
# Also check that the grading policy loaded
# Also check that the grading policy loaded
self
.
assertEqual
(
two_toys
.
grade_cutoffs
[
'C'
],
0.5999
)
self
.
assertEqual
(
two_toys
.
grade_cutoffs
[
'C'
],
0.5999
)
# Also check that keys from policy are run through the
# appropriate attribute maps -- 'graded' should be True, not 'true'
self
.
assertEqual
(
toy
.
metadata
[
'graded'
],
True
)
def
test_definition_loading
(
self
):
def
test_definition_loading
(
self
):
"""When two courses share the same org and course name and
"""When two courses share the same org and course name and
...
...
common/lib/xmodule/xmodule/xml_module.py
View file @
4f782aac
...
@@ -96,10 +96,13 @@ class XmlDescriptor(XModuleDescriptor):
...
@@ -96,10 +96,13 @@ class XmlDescriptor(XModuleDescriptor):
# A dictionary mapping xml attribute names AttrMaps that describe how
# A dictionary mapping xml attribute names AttrMaps that describe how
# to import and export them
# to import and export them
# Allow json to specify either the string "true", or the bool True. The string is preferred.
to_bool
=
lambda
val
:
val
==
'true'
or
val
==
True
from_bool
=
lambda
val
:
str
(
val
)
.
lower
()
bool_map
=
AttrMap
(
to_bool
,
from_bool
)
xml_attribute_map
=
{
xml_attribute_map
=
{
# type conversion: want True/False in python, "true"/"false" in xml
# type conversion: want True/False in python, "true"/"false" in xml
'graded'
:
AttrMap
(
lambda
val
:
val
==
'true'
,
'graded'
:
bool_map
,
lambda
val
:
str
(
val
)
.
lower
()),
}
}
...
@@ -232,6 +235,16 @@ class XmlDescriptor(XModuleDescriptor):
...
@@ -232,6 +235,16 @@ class XmlDescriptor(XModuleDescriptor):
@classmethod
@classmethod
def
apply_policy
(
cls
,
metadata
,
policy
):
"""
Add the keys in policy to metadata, after processing them
through the attrmap. Updates the metadata dict in place.
"""
for
attr
in
policy
:
attr_map
=
cls
.
xml_attribute_map
.
get
(
attr
,
AttrMap
())
metadata
[
attr
]
=
attr_map
.
from_xml
(
policy
[
attr
])
@classmethod
def
from_xml
(
cls
,
xml_data
,
system
,
org
=
None
,
course
=
None
):
def
from_xml
(
cls
,
xml_data
,
system
,
org
=
None
,
course
=
None
):
"""
"""
Creates an instance of this descriptor from the supplied xml_data.
Creates an instance of this descriptor from the supplied xml_data.
...
@@ -279,7 +292,7 @@ class XmlDescriptor(XModuleDescriptor):
...
@@ -279,7 +292,7 @@ class XmlDescriptor(XModuleDescriptor):
# Set/override any metadata specified by policy
# Set/override any metadata specified by policy
k
=
policy_key
(
location
)
k
=
policy_key
(
location
)
if
k
in
system
.
policy
:
if
k
in
system
.
policy
:
metadata
.
update
(
system
.
policy
[
k
])
cls
.
apply_policy
(
metadata
,
system
.
policy
[
k
])
return
cls
(
return
cls
(
system
,
system
,
...
...
common/test/data/toy/policies/2012_Fall.json
View file @
4f782aac
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
"course/2012_Fall"
:
{
"course/2012_Fall"
:
{
"graceperiod"
:
"2 days 5 hours 59 minutes 59 seconds"
,
"graceperiod"
:
"2 days 5 hours 59 minutes 59 seconds"
,
"start"
:
"2015-07-17T12:00"
,
"start"
:
"2015-07-17T12:00"
,
"display_name"
:
"Toy Course"
"display_name"
:
"Toy Course"
,
"graded"
:
"true"
},
},
"chapter/Overview"
:
{
"chapter/Overview"
:
{
"display_name"
:
"Overview"
"display_name"
:
"Overview"
...
...
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