diff --git a/app/assets/stylesheets/components/radios.scss b/app/assets/stylesheets/components/radios.scss index ca6b343dc..0b755e10f 100644 --- a/app/assets/stylesheets/components/radios.scss +++ b/app/assets/stylesheets/components/radios.scss @@ -111,3 +111,9 @@ } } + +.inline { + .multiple-choice { + margin-right: 15px; + } +} diff --git a/app/main/forms.py b/app/main/forms.py index 2945f0347..d5c6acdce 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -765,6 +765,21 @@ class LetterTemplatePostageForm(StripWhitespaceForm): ) +class LetterUploadPostageForm(StripWhitespaceForm): + postage = RadioField( + 'Choose the postage for this letter', + choices=[ + ('first', 'First class post'), + ('second', 'Second class post'), + ], + default='second', + validators=[DataRequired()] + ) + file_id = HiddenField( + validators=[DataRequired()] + ) + + class ForgotPasswordForm(StripWhitespaceForm): email_address = email_address(gov_user=False) diff --git a/app/main/views/uploads.py b/app/main/views/uploads.py index 665fce5a5..2ed2ae114 100644 --- a/app/main/views/uploads.py +++ b/app/main/views/uploads.py @@ -18,7 +18,7 @@ from requests import RequestException from app import current_service, notification_api_client, service_api_client from app.extensions import antivirus_client from app.main import main -from app.main.forms import PDFUploadForm +from app.main.forms import LetterUploadPostageForm, PDFUploadForm from app.main.views.jobs import view_jobs from app.s3_client.s3_letter_upload_client import ( get_letter_metadata, @@ -153,6 +153,12 @@ def uploaded_letter_preview(service_id, file_id): error = get_letter_validation_error(error_message, 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, @@ -172,6 +178,7 @@ def uploaded_letter_preview(service_id, file_id): status=status, file_id=file_id, error=error, + form=form, ) @@ -194,14 +201,20 @@ def send_uploaded_letter(service_id): if not (current_service.has_permission('letter') and current_service.has_permission('upload_letters')): abort(403) - file_id = request.form['file_id'] + 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') if metadata.get('status') != 'valid': abort(403) - notification_api_client.send_precompiled_letter(service_id, filename, file_id) + notification_api_client.send_precompiled_letter(service_id, filename, file_id, postage) return redirect(url_for( '.view_notification', diff --git a/app/notify_client/notification_api_client.py b/app/notify_client/notification_api_client.py index 793af02ef..0ce251f6b 100644 --- a/app/notify_client/notification_api_client.py +++ b/app/notify_client/notification_api_client.py @@ -59,11 +59,11 @@ class NotificationApiClient(NotifyAdminAPIClient): data = _attach_current_user(data) return self.post(url='/service/{}/send-notification'.format(service_id), data=data) - def send_precompiled_letter(self, service_id, filename, file_id): + def send_precompiled_letter(self, service_id, filename, file_id, postage): data = { 'filename': filename, 'file_id': file_id, - 'postage': 'second', + 'postage': postage, } data = _attach_current_user(data) return self.post(url='/service/{}/send-pdf-letter'.format(service_id), data=data) diff --git a/app/templates/components/radios.html b/app/templates/components/radios.html index dd56baba0..e41e57af4 100644 --- a/app/templates/components/radios.html +++ b/app/templates/components/radios.html @@ -1,7 +1,7 @@ {% from "components/select-input.html" import select, select_list, select_nested, select_wrapper, select_input %} -{% macro radios(field, hint=None, disable=[], option_hints={}, hide_legend=False) %} - {{ select(field, hint, disable, option_hints, hide_legend, input="radio") }} +{% macro radios(field, hint=None, disable=[], option_hints={}, hide_legend=False, inline=False) %} + {{ select(field, hint, disable, option_hints, hide_legend, input="radio", inline=inline) }} {% endmacro %} diff --git a/app/templates/components/select-input.html b/app/templates/components/select-input.html index f65647647..f8387c68e 100644 --- a/app/templates/components/select-input.html +++ b/app/templates/components/select-input.html @@ -1,6 +1,6 @@ -{% macro select(field, hint=None, disable=[], option_hints={}, hide_legend=False, collapsible_opts={}, legend_style="text", input="radio") %} +{% macro select(field, hint=None, disable=[], option_hints={}, hide_legend=False, collapsible_opts={}, legend_style="text", input="radio", inline=False) %} {% call select_wrapper( - field, hint, disable, option_hints, hide_legend, collapsible_opts, legend_style + field, hint, disable, option_hints, hide_legend, collapsible_opts, legend_style, inline=inline ) %} {% for option in field %} {{ select_input(option, disable, option_hints, input=input) }} @@ -35,13 +35,13 @@ {% endmacro %} -{% macro select_wrapper(field, hint=None, disable=[], option_hints={}, hide_legend=False, collapsible_opts={}, legend_style="text") %} +{% macro select_wrapper(field, hint=None, disable=[], option_hints={}, hide_legend=False, collapsible_opts={}, legend_style="text", inline=False) %} {% set is_collapsible = collapsible_opts|length %}