Have the CMS use the same XMLModuleStore for import that the LMS uses for reading content
This commit is contained in:
@@ -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})
|
||||
|
||||
Reference in New Issue
Block a user