Commit 7b3ab952 by Chris Dodge Committed by Joe Blaylock

give some debug message regarding why export might fail

Conflicts:

	common/lib/xmodule/xmodule/raw_module.py
parent c5d53473
......@@ -3,6 +3,7 @@ import json
import os
import tarfile
import shutil
import cgi
from tempfile import mkdtemp
from path import path
......@@ -27,7 +28,7 @@ from xmodule.modulestore import Location
from xmodule.contentstore.content import StaticContent
from xmodule.util.date_utils import get_default_time_display
from xmodule.modulestore import InvalidLocationError
from xmodule.exceptions import NotFoundError
from xmodule.exceptions import NotFoundError, SerializationError
from ..utils import get_url_reverse
from .access import get_location_and_verify_access
......@@ -332,16 +333,34 @@ def generate_export_course(request, org, course, name):
the course
"""
location = get_location_and_verify_access(request, org, course, name)
course_module = modulestore().get_item(location)
loc = Location(location)
export_file = NamedTemporaryFile(prefix=name + '.', suffix=".tar.gz")
root_dir = path(mkdtemp())
# export out to a tempdir
logging.debug('root = {0}'.format(root_dir))
try:
export_to_xml(modulestore('direct'), contentstore(), loc, root_dir, name, modulestore())
except SerializationError, e:
failed_item = modulestore().get_item(e.location)
parent_locs = modulestore().get_parent_locations(failed_item.location, None)
if len(parent_locs) > 0:
parent = modulestore().get_item(parent_locs[0])
parent_info = "Parent Display Name: {0}<br />Parent Identifier: {1}".format(parent.display_name, parent.location.name)
else:
parent_info = ''
return render_to_response('export.html', {
'context_course': course_module,
'successful_import_redirect_url': '',
'err_msg': "A courseware module has failed to convert to XML. Details: <br />Module Type: {0}<br />Display Name: {1}<br />Identifier: {2}<br />{3}".
format(failed_item.location.category, failed_item.display_name, failed_item.location.name, parent_info)
})
except Exception, e:
return render_to_response('export.html', {
'context_course': course_module,
'successful_import_redirect_url': '',
'err_msg': str(e)
})
logging.debug('tar file being generated at {0}'.format(export_file.name))
tar_file = tarfile.open(name=export_file.name, mode='w:gz')
......
......@@ -6,6 +6,24 @@
<%block name="title">${_("Course Export")}</%block>
<%block name="bodyclass">is-signedin course tools export</%block>
<%block name="jsextra">
% if err_msg:
<script type='text/javascript'>
$(document).ready(function() {
var defaultTitle = gettext('There has been an error with your export.');
var msg = "${err_msg}";
dialog = new CMS.Views.Alert.Confirmation({
title: defaultTitle,
message: msg,
intent: "error",
closeIcon: false
});
dialog.show();
})
</script>
%endif
</%block>
<%block name="content">
<div class="wrapper-mast wrapper">
<header class="mast has-subtitle">
......@@ -18,6 +36,7 @@
<div class="main-wrapper">
<div class="inner-wrapper">
<article class="export-overview">
<div class="description">
<h2>${_("About Exporting Courses")}</h2>
......
......@@ -13,6 +13,7 @@ class ProcessingError(Exception):
'''
pass
class InvalidVersionError(Exception):
"""
Tried to save an item with a location that a store cannot support (e.g., draft version
......@@ -21,3 +22,12 @@ class InvalidVersionError(Exception):
def __init__(self, location):
super(InvalidVersionError, self).__init__()
self.location = location
class SerializationError(Exception):
"""
Thrown when a module cannot be exported to XML
"""
def __init__(self, location, msg):
super(SerializationError, self).__init__(msg)
self.location = location
......@@ -4,6 +4,7 @@ from xmodule.xml_module import XmlDescriptor
import logging
import sys
from xblock.core import String, Scope
from exceptions import SerializationError
log = logging.getLogger(__name__)
......@@ -27,8 +28,27 @@ class RawDescriptor(XmlDescriptor, XMLEditingDescriptor):
# re-raise
lines = self.data.split('\n')
line, offset = err.position
msg = ("Unable to create xml for problem {loc}. "
msg = ("Unable to create xml for module {loc}. "
"Context: '{context}'".format(
context=lines[line - 1][offset - 40:offset + 40],
loc=self.location))
raise Exception, msg, sys.exc_info()[2]
raise SerializationError(self.location, msg)
class EmptyDataRawDescriptor(XmlDescriptor, XMLEditingDescriptor):
"""
Version of RawDescriptor for modules which may have no XML data,
but use XMLEditingDescriptor for import/export handling.
"""
data = String(default='', scope=Scope.content)
@classmethod
def definition_from_xml(cls, xml_object, system):
if len(xml_object) == 0 and len(xml_object.items()) == 0:
return {'data': ''}, []
return {'data': etree.tostring(xml_object, pretty_print=True, encoding='unicode')}, []
def definition_to_xml(self, resource_fs):
if self.data:
return etree.fromstring(self.data)
return etree.Element(self.category)
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