Narrowed a too wide try/except region in order to give more correct error messages. Changed the the strip() application to happen only on extracted author elements that actually have content. Fixes an inability to upload xml-only drafts with missing author country information.

- Legacy-Id: 13574
This commit is contained in:
Henrik Levkowetz 2017-06-09 20:12:44 +00:00
parent 22d83d2d2c
commit df2d0571c4

View file

@ -146,9 +146,12 @@ class SubmissionUploadForm(forms.Form):
for chunk in xml_file.chunks():
tf.write(chunk)
os.environ["XML_LIBRARY"] = settings.XML_LIBRARY
parser = xml2rfc.XmlRfcParser(tfn, quiet=True)
self.xmltree = parser.parse()
ok, errors = self.xmltree.validate()
try:
parser = xml2rfc.XmlRfcParser(tfn, quiet=True)
self.xmltree = parser.parse()
ok, errors = self.xmltree.validate()
except Exception as exc:
raise forms.ValidationError("An exception occurred when trying to process the XML file: %s" % exc)
if not ok:
# Each error has properties:
#
@ -180,16 +183,18 @@ class SubmissionUploadForm(forms.Form):
self.abstract = unidecode(self.abstract)
author_info = self.xmlroot.findall('front/author')
for author in author_info:
self.authors.append({
"name": author.attrib.get('fullname').strip(),
"email": author.findtext('address/email').strip(),
"affiliation": author.findtext('organization').strip(),
"country": author.findtext('address/postal/country').strip(),
})
info = {
"name": author.attrib.get('fullname'),
"email": author.findtext('address/email'),
"affiliation": author.findtext('organization'),
"country": author.findtext('address/postal/country'),
}
for item in info:
if info[item]:
info[item] = info[item].strip()
self.authors.append(info)
except forms.ValidationError:
raise
except Exception as e:
raise forms.ValidationError("An exception occurred when trying to process the XML file: %s" % e)
finally:
os.close(tfh)
os.unlink(tfn)