def send_uploaded_letter(service_id, file_id): if not current_service.has_permission('letter'): abort(403) metadata = get_letter_metadata(service_id, file_id) if metadata.get('status') != 'valid': abort(403) postal_address = PostalAddress(metadata.get('recipient')) form = LetterUploadPostageForm(postage_zone=postal_address.postage) if not form.validate_on_submit(): return uploaded_letter_preview(service_id, file_id) notification_api_client.send_precompiled_letter( service_id, metadata.get('filename'), file_id, form.postage.data, postal_address.raw_address, ) return redirect( url_for( '.view_notification', service_id=service_id, notification_id=file_id, ))
def send_uploaded_letter(service_id): if not (current_service.has_permission('letter') and current_service.has_permission('upload_letters')): abort(403) form = LetterUploadPostageForm() file_id = form.file_id.data if not form.validate_on_submit(): return uploaded_letter_preview(service_id, file_id) postage = form.postage.data metadata = get_letter_metadata(service_id, file_id) filename = metadata.get('filename') recipient_address = metadata.get('recipient') if metadata.get('status') != 'valid': abort(403) notification_api_client.send_precompiled_letter(service_id, filename, file_id, postage, recipient_address) return redirect(url_for( '.view_notification', service_id=service_id, notification_id=file_id, ))
def uploaded_letter_preview(service_id, file_id): re_upload_form = PDFUploadForm() try: metadata = get_letter_metadata(service_id, file_id) except ClientError as e: # if the file's not there, it's probably because we've already created the notification and the letter has been # moved to the normal letters-pdf bucket. So lets just bounce out to the notification page if e.response['Error']['Code'] == 'NoSuchKey': return redirect( url_for( '.view_notification', service_id=service_id, notification_id=file_id, )) else: raise original_filename = metadata.get('filename') page_count = metadata.get('page_count') status = metadata.get('status') error_shortcode = metadata.get('message') invalid_pages = metadata.get('invalid_pages') postal_address = PostalAddress(metadata.get('recipient', '')) if invalid_pages: invalid_pages = json.loads(invalid_pages) error_message = get_letter_validation_error(error_shortcode, invalid_pages, page_count) template_dict = service_api_client.get_precompiled_template(service_id) # Override pre compiled letter template postage to none as it has not yet been picked even though # the pre compiled letter template has its postage set as second class as the DB currently requires # a non null value of postage for letter templates template_dict['postage'] = None form = LetterUploadPostageForm(postage_zone=postal_address.postage) template = get_template(template_dict, service_id, letter_preview_url=url_for( '.view_letter_upload_as_preview', service_id=service_id, file_id=file_id), page_count=page_count) return render_template( 'views/uploads/preview.html', original_filename=original_filename, template=template, status=status, file_id=file_id, message=error_message, error_code=error_shortcode, form=form, allowed_file_extensions=Spreadsheet.ALLOWED_FILE_EXTENSIONS, postal_address=postal_address, re_upload_form=re_upload_form)
def uploaded_letter_preview(service_id, file_id): re_upload_form = PDFUploadForm() metadata = get_letter_metadata(service_id, file_id) original_filename = metadata.get('filename') page_count = metadata.get('page_count') status = metadata.get('status') error_shortcode = metadata.get('message') invalid_pages = metadata.get('invalid_pages') recipient = format_recipient(metadata.get('recipient', '')) if invalid_pages: invalid_pages = json.loads(invalid_pages) error_message = get_letter_validation_error(error_shortcode, invalid_pages, page_count) template_dict = service_api_client.get_precompiled_template(service_id) # Override pre compiled letter template postage to none as it has not yet been picked even though # the pre compiled letter template has its postage set as second class as the DB currently requires # a non null value of postage for letter templates template_dict['postage'] = None form = LetterUploadPostageForm() template = get_template( template_dict, service_id, letter_preview_url=url_for( '.view_letter_upload_as_preview', service_id=service_id, file_id=file_id ), page_count=page_count ) return render_template( 'views/uploads/preview.html', original_filename=original_filename, template=template, status=status, file_id=file_id, message=error_message, error_code=error_shortcode, form=form, recipient=recipient, re_upload_form=re_upload_form )