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

@@ -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):