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
5cd388d6
Commit
5cd388d6
authored
Jun 28, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Have the CMS use the same XMLModuleStore for import that the LMS uses for reading content
parent
7d16dbbc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
37 deletions
+16
-37
cms/djangoapps/contentstore/management/commands/import.py
+9
-32
cms/djangoapps/contentstore/views.py
+1
-1
common/lib/keystore/__init__.py
+2
-2
common/lib/keystore/xml.py
+4
-2
No files found.
cms/djangoapps/contentstore/management/commands/import.py
View file @
5cd388d6
...
...
@@ -4,12 +4,8 @@
from
django.core.management.base
import
BaseCommand
,
CommandError
from
keystore.django
import
keystore
from
raw_module
import
RawDescriptor
from
lxml
import
etree
from
fs.osfs
import
OSFS
from
path
import
path
from
x_module
import
XModuleDescriptor
,
XMLParsingSystem
from
keystore.xml
import
XMLModuleStore
unnamed_modules
=
0
...
...
@@ -26,30 +22,11 @@ class Command(BaseCommand):
raise
CommandError
(
"import requires 3 arguments: <org> <course> <data directory>"
)
org
,
course
,
data_dir
=
args
data_dir
=
path
(
data_dir
)
with
open
(
data_dir
/
"course.xml"
)
as
course_file
:
class
ImportSystem
(
XMLParsingSystem
):
def
__init__
(
self
):
def
process_xml
(
xml
):
try
:
xml_data
=
etree
.
fromstring
(
xml
)
except
:
raise
CommandError
(
"Unable to parse xml: "
+
xml
)
if
not
xml_data
.
get
(
'name'
):
global
unnamed_modules
unnamed_modules
+=
1
xml_data
.
set
(
'name'
,
'{tag}_{count}'
.
format
(
tag
=
xml_data
.
tag
,
count
=
unnamed_modules
))
module
=
XModuleDescriptor
.
load_from_xml
(
etree
.
tostring
(
xml_data
),
self
,
org
,
course
,
RawDescriptor
)
keystore
()
.
create_item
(
module
.
url
)
if
'data'
in
module
.
definition
:
keystore
()
.
update_item
(
module
.
url
,
module
.
definition
[
'data'
])
if
'children'
in
module
.
definition
:
keystore
()
.
update_children
(
module
.
url
,
module
.
definition
[
'children'
])
return
module
XMLParsingSystem
.
__init__
(
self
,
keystore
()
.
get_item
,
OSFS
(
data_dir
),
process_xml
)
ImportSystem
()
.
process_xml
(
course_file
.
read
())
module_store
=
XMLModuleStore
(
org
,
course
,
data_dir
,
'xmodule.raw_module.RawDescriptor'
)
for
module
in
module_store
.
modules
.
itervalues
():
keystore
()
.
create_item
(
module
.
url
)
if
'data'
in
module
.
definition
:
keystore
()
.
update_item
(
module
.
url
,
module
.
definition
[
'data'
])
if
'children'
in
module
.
definition
:
keystore
()
.
update_children
(
module
.
url
,
module
.
definition
[
'children'
])
cms/djangoapps/contentstore/views.py
View file @
5cd388d6
...
...
@@ -10,7 +10,7 @@ def index(request):
# TODO (cpennington): These need to be read in from the active user
org
=
'mit.edu'
course
=
'6002xs12'
name
=
'6.002
Spring
2012'
name
=
'6.002
_Spring_
2012'
course
=
keystore
()
.
get_item
([
'i4x'
,
org
,
course
,
'course'
,
name
])
weeks
=
course
.
get_children
()
return
render_to_response
(
'index.html'
,
{
'weeks'
:
weeks
})
...
...
common/lib/keystore/__init__.py
View file @
5cd388d6
...
...
@@ -15,7 +15,7 @@ URL_RE = re.compile("""
(/(?P<revision>[^/]+))?
"""
,
re
.
VERBOSE
)
INVALID_CHARS
=
re
.
compile
(
r"[^\w-]"
)
INVALID_CHARS
=
re
.
compile
(
r"[^\w
.
-]"
)
class
Location
(
object
):
...
...
@@ -55,7 +55,7 @@ class Location(object):
In both the dict and list forms, the revision is optional, and can be ommitted.
Components must be composed of alphanumeric characters, or the characters
_, and -
Components must be composed of alphanumeric characters, or the characters
'_', '-', and '.'
Components may be set to None, which may be interpreted by some contexts to mean
wildcard selection
...
...
common/lib/keystore/xml.py
View file @
5cd388d6
...
...
@@ -10,6 +10,8 @@ from .exceptions import ItemNotFoundError
etree
.
set_default_parser
(
etree
.
XMLParser
(
dtd_validation
=
False
,
load_dtd
=
False
,
remove_comments
=
True
))
log
=
logging
.
getLogger
(
__name__
)
class
XMLModuleStore
(
ModuleStore
):
"""
...
...
@@ -23,7 +25,7 @@ class XMLModuleStore(ModuleStore):
class_
=
getattr
(
import_module
(
module_path
),
class_name
)
self
.
default_class
=
class_
with
open
(
data_dir
/
"course.xml"
)
as
course_file
:
with
open
(
self
.
data_dir
/
"course.xml"
)
as
course_file
:
class
ImportSystem
(
XMLParsingSystem
):
def
__init__
(
self
,
keystore
):
self
.
unnamed_modules
=
0
...
...
@@ -32,7 +34,7 @@ class XMLModuleStore(ModuleStore):
try
:
xml_data
=
etree
.
fromstring
(
xml
)
except
:
print
xml
log
.
exception
(
"Unable to parse xml:"
+
xml
)
raise
if
xml_data
.
get
(
'name'
):
xml_data
.
set
(
'slug'
,
Location
.
clean
(
xml_data
.
get
(
'name'
)))
...
...
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