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
241d445f
Commit
241d445f
authored
Aug 10, 2012
by
ichuang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changes to xml_module to allow problem metadata to be added via <meta>
parent
f6e84e84
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
3 deletions
+26
-3
common/lib/xmodule/xmodule/xml_module.py
+26
-3
No files found.
common/lib/xmodule/xmodule/xml_module.py
View file @
241d445f
from
xmodule.x_module
import
XModuleDescriptor
from
xmodule.x_module
import
XModuleDescriptor
from
xmodule.modulestore
import
Location
from
xmodule.modulestore
import
Location
from
lxml
import
etree
from
lxml
import
etree
import
json
import
copy
import
copy
import
logging
import
logging
import
traceback
import
traceback
...
@@ -32,7 +33,15 @@ def is_pointer_tag(xml_obj):
...
@@ -32,7 +33,15 @@ def is_pointer_tag(xml_obj):
actual_attr
=
set
(
xml_obj
.
attrib
.
keys
())
actual_attr
=
set
(
xml_obj
.
attrib
.
keys
())
return
len
(
xml_obj
)
==
0
and
actual_attr
==
expected_attr
return
len
(
xml_obj
)
==
0
and
actual_attr
==
expected_attr
def
get_metadata_from_xml
(
xml_object
,
remove
=
True
):
meta
=
xml_object
.
find
(
'meta'
)
if
meta
is
None
:
return
''
dmdata
=
meta
.
text
log
.
debug
(
'meta for
%
s loaded:
%
s'
%
(
xml_object
,
dmdata
))
if
remove
:
xml_object
.
remove
(
meta
)
return
dmdata
_AttrMapBase
=
namedtuple
(
'_AttrMap'
,
'from_xml to_xml'
)
_AttrMapBase
=
namedtuple
(
'_AttrMap'
,
'from_xml to_xml'
)
...
@@ -180,8 +189,11 @@ class XmlDescriptor(XModuleDescriptor):
...
@@ -180,8 +189,11 @@ class XmlDescriptor(XModuleDescriptor):
definition_xml
=
cls
.
load_file
(
filepath
,
system
.
resources_fs
,
location
)
definition_xml
=
cls
.
load_file
(
filepath
,
system
.
resources_fs
,
location
)
definition_metadata
=
get_metadata_from_xml
(
definition_xml
)
cls
.
clean_metadata_from_xml
(
definition_xml
)
cls
.
clean_metadata_from_xml
(
definition_xml
)
definition
=
cls
.
definition_from_xml
(
definition_xml
,
system
)
definition
=
cls
.
definition_from_xml
(
definition_xml
,
system
)
if
definition_metadata
:
definition
[
'definition_metadata'
]
=
definition_metadata
# TODO (ichuang): remove this after migration
# TODO (ichuang): remove this after migration
# for Fall 2012 LMS migration: keep filename (and unmangled filename)
# for Fall 2012 LMS migration: keep filename (and unmangled filename)
...
@@ -236,9 +248,9 @@ class XmlDescriptor(XModuleDescriptor):
...
@@ -236,9 +248,9 @@ class XmlDescriptor(XModuleDescriptor):
filepath
=
cls
.
_format_filepath
(
xml_object
.
tag
,
url_name
)
filepath
=
cls
.
_format_filepath
(
xml_object
.
tag
,
url_name
)
definition_xml
=
cls
.
load_file
(
filepath
,
system
.
resources_fs
,
location
)
definition_xml
=
cls
.
load_file
(
filepath
,
system
.
resources_fs
,
location
)
else
:
else
:
definition_xml
=
xml_object
definition_xml
=
xml_object
# this is just a pointer, not the real definition content
definition
=
cls
.
load_definition
(
definition_xml
,
system
,
location
)
definition
=
cls
.
load_definition
(
definition_xml
,
system
,
location
)
# note this removes metadata
# VS[compat] -- make Ike's github preview links work in both old and
# VS[compat] -- make Ike's github preview links work in both old and
# new file layouts
# new file layouts
if
is_pointer_tag
(
xml_object
):
if
is_pointer_tag
(
xml_object
):
...
@@ -246,6 +258,17 @@ class XmlDescriptor(XModuleDescriptor):
...
@@ -246,6 +258,17 @@ class XmlDescriptor(XModuleDescriptor):
definition
[
'filename'
]
=
[
filepath
,
filepath
]
definition
[
'filename'
]
=
[
filepath
,
filepath
]
metadata
=
cls
.
load_metadata
(
definition_xml
)
metadata
=
cls
.
load_metadata
(
definition_xml
)
# move definition metadata into dict
dmdata
=
definition
.
get
(
'definition_metadata'
,
''
)
if
dmdata
:
metadata
[
'definition_metadata_raw'
]
=
dmdata
try
:
metadata
.
update
(
json
.
loads
(
dmdata
))
except
Exception
as
err
:
log
.
debug
(
'Error
%
s in loading metadata
%
s'
%
(
err
,
dmdata
))
metadata
[
'definition_metadata_err'
]
=
str
(
err
)
return
cls
(
return
cls
(
system
,
system
,
definition
,
definition
,
...
...
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