Improved the error reporting for invalid xml file submissions.
- Legacy-Id: 9916
This commit is contained in:
parent
cfb7dc3dc8
commit
cdb0d24aed
|
@ -136,7 +136,8 @@ class SubmissionUploadForm(forms.Form):
|
||||||
if self.cleaned_data.get('xml'):
|
if self.cleaned_data.get('xml'):
|
||||||
#if not self.cleaned_data.get('txt'):
|
#if not self.cleaned_data.get('txt'):
|
||||||
xml_file = self.cleaned_data.get('xml')
|
xml_file = self.cleaned_data.get('xml')
|
||||||
tfh, tfn = tempfile.mkstemp(suffix='.xml')
|
name, ext = os.path.splitext(os.path.basename(xml_file.name))
|
||||||
|
tfh, tfn = tempfile.mkstemp(prefix=name+'-', suffix='.xml')
|
||||||
try:
|
try:
|
||||||
# We need to write the xml file to disk in order to hand it
|
# We need to write the xml file to disk in order to hand it
|
||||||
# over to the xml parser. XXX FIXME: investigate updating
|
# over to the xml parser. XXX FIXME: investigate updating
|
||||||
|
@ -149,8 +150,21 @@ class SubmissionUploadForm(forms.Form):
|
||||||
parser = xml2rfc.XmlRfcParser(tfn, quiet=True)
|
parser = xml2rfc.XmlRfcParser(tfn, quiet=True)
|
||||||
self.xmltree = parser.parse()
|
self.xmltree = parser.parse()
|
||||||
ok, errors = self.xmltree.validate()
|
ok, errors = self.xmltree.validate()
|
||||||
|
debug.type('errors')
|
||||||
if not ok:
|
if not ok:
|
||||||
raise forms.ValidationError(errors)
|
# Each error has properties:
|
||||||
|
#
|
||||||
|
# message: the message text
|
||||||
|
# domain: the domain ID (see lxml.etree.ErrorDomains)
|
||||||
|
# type: the message type ID (see lxml.etree.ErrorTypes)
|
||||||
|
# level: the log level ID (see lxml.etree.ErrorLevels)
|
||||||
|
# line: the line at which the message originated (if applicable)
|
||||||
|
# column: the character column at which the message originated (if applicable)
|
||||||
|
# filename: the name of the file in which the message originated (if applicable)
|
||||||
|
raise forms.ValidationError(
|
||||||
|
[ forms.ValidationError("One or more XML validation errors occurred when processing the XML file:") ] +
|
||||||
|
[ forms.ValidationError("%s: Line %s: %s" % (xml_file.name, e.line, e.message), code="%s"%e.type) for e in errors ]
|
||||||
|
)
|
||||||
self.xmlroot = self.xmltree.getroot()
|
self.xmlroot = self.xmltree.getroot()
|
||||||
draftname = self.xmlroot.attrib.get('docName')
|
draftname = self.xmlroot.attrib.get('docName')
|
||||||
revmatch = re.search("-[0-9][0-9]$", draftname)
|
revmatch = re.search("-[0-9][0-9]$", draftname)
|
||||||
|
@ -174,8 +188,10 @@ class SubmissionUploadForm(forms.Form):
|
||||||
self.author_list.append(author_dict)
|
self.author_list.append(author_dict)
|
||||||
line = "%(full_name)s <%(email)s>" % author_dict
|
line = "%(full_name)s <%(email)s>" % author_dict
|
||||||
self.authors.append(line)
|
self.authors.append(line)
|
||||||
|
except forms.ValidationError:
|
||||||
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise forms.ValidationError("Exception: %s" % e)
|
raise forms.ValidationError("Exception when trying to process the XML file: %s" % e)
|
||||||
finally:
|
finally:
|
||||||
os.close(tfh)
|
os.close(tfh)
|
||||||
os.unlink(tfn)
|
os.unlink(tfn)
|
||||||
|
|
Loading…
Reference in a new issue