handle invalid upload errors correctly

previously it assumed that invalid_pages would always exist, however it
might be `None` if the error isn't on a specific page. Errors on
specific pages include a page not being A4 or content being outside the
boundary. Errors not on specific pages include the file not being a pdf,
or containing too many pages
This commit is contained in:
Leo Hemsted
2020-01-27 15:07:40 +00:00
parent da2bc29b40
commit 4e1fcfbff1
2 changed files with 5 additions and 3 deletions

View File

@@ -629,13 +629,15 @@ LETTER_VALIDATION_MESSAGES = {
def get_letter_validation_error(validation_message, invalid_pages=None, page_count=None):
if not invalid_pages:
invalid_pages = []
if validation_message not in LETTER_VALIDATION_MESSAGES:
return {'title': 'Validation failed'}
invalid_pages_are_or_is = 'is' if len(invalid_pages) == 1 else 'are'
invalid_pages = unescaped_formatted_list(
invalid_pages or [],
invalid_pages,
before_each='',
after_each='',
prefix='page',