Refactor process_letter_notification to make the code easier to read.

- Separated the logic of precompiled and template letters.
- Remove the check for research mode, research mode is not relevant to api calls. The test key is used for testing.
Refactor upload_pdf_letter to accept a precompile boolean to save a query to template.
This commit is contained in:
Rebecca Law
2018-04-09 13:56:44 +01:00
parent e7bd6380ab
commit b73bf4220f
4 changed files with 95 additions and 134 deletions

View File

@@ -64,16 +64,16 @@ def get_reference_from_filename(filename):
return filename_parts[1]
def upload_letter_pdf(notification, pdf_data):
def upload_letter_pdf(notification, pdf_data, precompiled=False):
current_app.logger.info("PDF Letter {} reference {} created at {}, {} bytes".format(
notification.id, notification.reference, notification.created_at, len(pdf_data)))
upload_file_name = get_letter_pdf_filename(
notification.reference,
notification.service.crown,
is_scan_letter=notification.template.is_precompiled_letter)
is_scan_letter=precompiled)
if notification.template.is_precompiled_letter:
if precompiled:
bucket_name = current_app.config['LETTERS_SCAN_BUCKET_NAME']
else:
bucket_name = current_app.config['LETTERS_PDF_BUCKET_NAME']