feat: useful error when submission has inconsistent date (#8576)
* chore: handle errors in app-configure-blobstore.py * feat: sensible error for inconsistent <date>
This commit is contained in:
parent
7f3488c5c2
commit
fb310e5ce2
|
@ -58,7 +58,7 @@ from ietf.utils.draft import PlaintextDraft
|
||||||
from ietf.utils.mail import is_valid_email
|
from ietf.utils.mail import is_valid_email
|
||||||
from ietf.utils.text import parse_unicode, normalize_text
|
from ietf.utils.text import parse_unicode, normalize_text
|
||||||
from ietf.utils.timezone import date_today
|
from ietf.utils.timezone import date_today
|
||||||
from ietf.utils.xmldraft import XMLDraft
|
from ietf.utils.xmldraft import InvalidMetadataError, XMLDraft
|
||||||
from ietf.person.name import unidecode_name
|
from ietf.person.name import unidecode_name
|
||||||
|
|
||||||
|
|
||||||
|
@ -1201,6 +1201,11 @@ def process_submission_xml(filename, revision):
|
||||||
if not title:
|
if not title:
|
||||||
raise SubmissionError("Could not extract a valid title from the XML")
|
raise SubmissionError("Could not extract a valid title from the XML")
|
||||||
|
|
||||||
|
try:
|
||||||
|
document_date = xml_draft.get_creation_date()
|
||||||
|
except InvalidMetadataError as err:
|
||||||
|
raise SubmissionError(str(err)) from err
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"filename": xml_draft.filename,
|
"filename": xml_draft.filename,
|
||||||
"rev": xml_draft.revision,
|
"rev": xml_draft.revision,
|
||||||
|
@ -1210,7 +1215,7 @@ def process_submission_xml(filename, revision):
|
||||||
for auth in xml_draft.get_author_list()
|
for auth in xml_draft.get_author_list()
|
||||||
],
|
],
|
||||||
"abstract": None, # not supported from XML
|
"abstract": None, # not supported from XML
|
||||||
"document_date": xml_draft.get_creation_date(),
|
"document_date": document_date,
|
||||||
"pages": None, # not supported from XML
|
"pages": None, # not supported from XML
|
||||||
"words": None, # not supported from XML
|
"words": None, # not supported from XML
|
||||||
"first_two_pages": None, # not supported from XML
|
"first_two_pages": None, # not supported from XML
|
||||||
|
|
|
@ -159,7 +159,16 @@ class XMLDraft(Draft):
|
||||||
day = today.day
|
day = today.day
|
||||||
else:
|
else:
|
||||||
day = 15
|
day = 15
|
||||||
return datetime.date(year, month, day)
|
try:
|
||||||
|
creation_date = datetime.date(year, month, day)
|
||||||
|
except Exception:
|
||||||
|
raise InvalidMetadataError(
|
||||||
|
"The <date> element in the <front> section specified an incomplete date "
|
||||||
|
"that was not consistent with today's date. If you specify only a year, "
|
||||||
|
"it must be the four-digit current year. To use today's date, omit the "
|
||||||
|
"date tag or use <date/>."
|
||||||
|
)
|
||||||
|
return creation_date
|
||||||
|
|
||||||
def get_creation_date(self):
|
def get_creation_date(self):
|
||||||
return self.parse_creation_date(self.xmlroot.find("front/date"))
|
return self.parse_creation_date(self.xmlroot.find("front/date"))
|
||||||
|
@ -269,3 +278,7 @@ class XMLParseError(Exception):
|
||||||
class InvalidXMLError(Exception):
|
class InvalidXMLError(Exception):
|
||||||
"""File is not valid XML"""
|
"""File is not valid XML"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidMetadataError(Exception):
|
||||||
|
"""XML is well-formed but has invalid metadata"""
|
||||||
|
|
Loading…
Reference in a new issue