Commit 5cd388d6 by Calen Pennington

Have the CMS use the same XMLModuleStore for import that the LMS uses for reading content

parent 7d16dbbc
......@@ -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'])
......@@ -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})
......
......@@ -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
......
......@@ -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')))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment