mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 16:24:08 -04:00
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:
@@ -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
|
||||
|
||||
@@ -45,15 +45,16 @@ def upload_letter_to_s3(
|
||||
|
||||
|
||||
class LetterMetadata:
|
||||
KEYS_TO_DECODE = ["filename"]
|
||||
KEYS_TO_DECODE = ["filename", "recipient"]
|
||||
|
||||
def __init__(self, metadata):
|
||||
self._metadata = metadata
|
||||
|
||||
def get(self, key, default=None):
|
||||
if key in self.KEYS_TO_DECODE:
|
||||
return urllib.parse.unquote(self._metadata.get(key, default))
|
||||
return self._metadata.get(key, default)
|
||||
value = self._metadata.get(key, default)
|
||||
if value and key in self.KEYS_TO_DECODE:
|
||||
value = urllib.parse.unquote(value)
|
||||
return value
|
||||
|
||||
|
||||
def get_letter_pdf_and_metadata(service_id, file_id):
|
||||
|
||||
Reference in New Issue
Block a user