Move recipient decoding into LetterMetadata class

This is for consistency with how we do it for filenames in the previous
commit and moves the decoding into the `LetterMetadata` class for
abstracting this behaviour.

Small refactor of the LetterMetadata class needed to handle None case as
recipient can be None.
This commit is contained in:
David McDonald
2020-05-18 15:44:20 +01:00
parent 7923760345
commit 387fcfda3f
3 changed files with 13 additions and 13 deletions

View File

@@ -1,7 +1,6 @@
import base64
import itertools
import json
import urllib
import uuid
from io import BytesIO
from zipfile import BadZipFile
@@ -192,14 +191,12 @@ def _get_error_from_upload_form(form_errors):
def format_recipient(address):
'''
To format the recipient we need to:
- decode, address is url encoded
- remove new line characters
- remove whitespace around the lines
- join the address lines, separated by a comma
'''
if not address:
return address
address = urllib.parse.unquote(address)
stripped_address_lines_no_trailing_commas = [
line.lstrip().rstrip(' ,')
for line in address.splitlines() if line