From daf3eed4eec69c4709e73c0b5288274e46b7e294 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Tue, 26 Jun 2012 12:14:18 -0400 Subject: [PATCH] Handle unnamed modules during import --- .../contentstore/management/commands/import.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/cms/djangoapps/contentstore/management/commands/import.py b/cms/djangoapps/contentstore/management/commands/import.py index ca94c2af5a..0ce0ce03fe 100644 --- a/cms/djangoapps/contentstore/management/commands/import.py +++ b/cms/djangoapps/contentstore/management/commands/import.py @@ -5,10 +5,15 @@ from django.core.management.base import BaseCommand from keystore.django import keystore from raw_module import RawDescriptor +from lxml import etree from path import path from x_module import XModuleDescriptor, DescriptorSystem +unnamed_modules = 0 + +etree.set_default_parser(etree.XMLParser(dtd_validation=False, load_dtd=False, + remove_comments=True)) class Command(BaseCommand): help = \ @@ -22,7 +27,18 @@ class Command(BaseCommand): system = DescriptorSystem(keystore().get_item) def process_xml(xml): - module = XModuleDescriptor.load_from_xml(xml, system, org, course, RawDescriptor) + try: + xml_data = etree.fromstring(xml) + except: + print xml + raise + if not xml_data.get('name'): + global unnamed_modules + unnamed_modules += 1 + xml_data.set('name', 'Unnamed module %d' % unnamed_modules) + + + module = XModuleDescriptor.load_from_xml(etree.tostring(xml_data), system, org, course, RawDescriptor) keystore().create_item(module.url) if 'data' in module.definition: keystore().update_item(module.url, module.definition['data'])