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
be40d8bb
Commit
be40d8bb
authored
12 years ago
by
Calen Pennington
Browse files
Options
Downloads
Patches
Plain Diff
Make sure that xml_module definition xml doesn't have any metadata sprinkled in with it
parent
c57833da
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/lib/xmodule/xml_module.py
+25
-2
25 additions, 2 deletions
common/lib/xmodule/xml_module.py
with
25 additions
and
2 deletions
common/lib/xmodule/xml_module.py
+
25
−
2
View file @
be40d8bb
from
collections
import
MutableMapping
from
xmodule.x_module
import
XModuleDescriptor
from
lxml
import
etree
import
copy
class
LazyLoadingDict
(
MutableMapping
):
...
...
@@ -41,6 +42,10 @@ class LazyLoadingDict(MutableMapping):
self
.
load
()
return
iter
(
self
.
_contents
)
def
__repr__
(
self
):
self
.
load
()
return
repr
(
self
.
_contents
)
def
load
(
self
):
if
self
.
_loaded
:
return
...
...
@@ -59,6 +64,11 @@ class XmlDescriptor(XModuleDescriptor):
# Extension to append to filename paths
filename_extension
=
'
xml
'
# The attributes will be removed from the definition xml passed
# to definition_from_xml, and from the xml returned by definition_to_xml
metadata_attributes
=
(
'
format
'
,
'
graceperiod
'
,
'
showanswer
'
,
'
rerandomize
'
,
'
due
'
,
'
graded
'
,
'
name
'
,
'
slug
'
)
@classmethod
def
definition_from_xml
(
cls
,
xml_object
,
system
):
"""
...
...
@@ -69,6 +79,15 @@ class XmlDescriptor(XModuleDescriptor):
"""
raise
NotImplementedError
(
"
%s does not implement definition_from_xml
"
%
cls
.
__name__
)
@classmethod
def
clean_metadata_from_xml
(
cls
,
xml_object
):
"""
Remove any attribute named in self.metadata_attributes from the supplied xml_object
"""
for
attr
in
cls
.
metadata_attributes
:
if
xml_object
.
get
(
attr
)
is
not
None
:
del
xml_object
.
attrib
[
attr
]
@classmethod
def
from_xml
(
cls
,
xml_data
,
system
,
org
=
None
,
course
=
None
):
"""
...
...
@@ -101,11 +120,14 @@ class XmlDescriptor(XModuleDescriptor):
def
definition_loader
():
filename
=
xml_object
.
get
(
'
filename
'
)
if
filename
is
None
:
return
cls
.
definition_from_xml
(
xml_object
,
system
)
definition_xml
=
copy
.
deepcopy
(
xml_object
)
else
:
filepath
=
cls
.
_format_filepath
(
xml_object
.
tag
,
filename
)
with
system
.
resources_fs
.
open
(
filepath
)
as
file
:
return
cls
.
definition_from_xml
(
etree
.
parse
(
file
).
getroot
(),
system
)
definition_xml
=
etree
.
parse
(
file
).
getroot
()
cls
.
clean_metadata_from_xml
(
definition_xml
)
return
cls
.
definition_from_xml
(
definition_xml
,
system
)
return
cls
(
system
,
...
...
@@ -134,6 +156,7 @@ class XmlDescriptor(XModuleDescriptor):
using the from_xml method with the same system, org, and course
"""
xml_object
=
self
.
definition_to_xml
(
resource_fs
)
self
.
__class__
.
clean_metadata_from_xml
(
xml_object
)
# Put content in a separate file if it's large (has more than 5 descendent tags)
if
len
(
list
(
xml_object
.
iter
()))
>
5
:
...
...
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