Commit 21ba5019 by Calen Pennington

Revert "Make import work via mako again, to unblock others while I work on…

Revert "Make import work via mako again, to unblock others while I work on making the LMS work using XModuleDescriptors"

This reverts commit 6fdf44fe.
parent 3c60d1a9
...@@ -7,7 +7,6 @@ from keystore.django import keystore ...@@ -7,7 +7,6 @@ from keystore.django import keystore
from raw_module import RawDescriptor from raw_module import RawDescriptor
from lxml import etree from lxml import etree
from fs.osfs import OSFS from fs.osfs import OSFS
from mako.lookup import TemplateLookup
from path import path from path import path
from x_module import XModuleDescriptor, XMLParsingSystem from x_module import XModuleDescriptor, XMLParsingSystem
...@@ -28,32 +27,30 @@ class Command(BaseCommand): ...@@ -28,32 +27,30 @@ class Command(BaseCommand):
org, course, data_dir = args org, course, data_dir = args
data_dir = path(data_dir) data_dir = path(data_dir)
with open(data_dir / "course.xml") as course_file:
class ImportSystem(XMLParsingSystem):
def __init__(self): class ImportSystem(XMLParsingSystem):
self.load_item = keystore().get_item def __init__(self):
self.fs = OSFS(data_dir) self.load_item = keystore().get_item
self.fs = OSFS(data_dir)
def process_xml(self, xml):
try: def process_xml(self, xml):
xml_data = etree.fromstring(xml) try:
except: xml_data = etree.fromstring(xml)
raise CommandError("Unable to parse xml: " + xml) except:
raise CommandError("Unable to parse xml: " + xml)
if not xml_data.get('name'):
global unnamed_modules if not xml_data.get('name'):
unnamed_modules += 1 global unnamed_modules
xml_data.set('name', '{tag}_{count}'.format(tag=xml_data.tag, count=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) module = XModuleDescriptor.load_from_xml(etree.tostring(xml_data), self, org, course, RawDescriptor)
if 'data' in module.definition: keystore().create_item(module.url)
keystore().update_item(module.url, module.definition['data']) if 'data' in module.definition:
if 'children' in module.definition: keystore().update_item(module.url, module.definition['data'])
keystore().update_children(module.url, module.definition['children']) if 'children' in module.definition:
return module keystore().update_children(module.url, module.definition['children'])
return module
lookup = TemplateLookup(directories=[data_dir])
template = lookup.get_template("course.xml") ImportSystem().process_xml(course_file.read())
course_string = template.render(groups=[])
ImportSystem().process_xml(course_string)
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