From 49ec2d77bb17f4bdfa1d5058b298f5a991cae272 Mon Sep 17 00:00:00 2001 From: Tom Byers Date: Thu, 9 Apr 2020 16:31:19 +0100 Subject: [PATCH] Update all single field checkboxes Includes adding some code to govukCheckboxesField to add a single boolean-like option by default, if there are no choices added. --- app/main/forms.py | 10 +++++----- app/main/views/platform_admin.py | 6 ++++-- app/templates/views/platform-admin/services.html | 3 +-- .../email-reply-to/_verify-updates.html | 4 +--- .../views/service-settings/email-reply-to/add.html | 4 +--- .../views/service-settings/email-reply-to/edit.html | 4 +--- .../views/service-settings/letter-contact/add.html | 4 +--- .../views/service-settings/letter-contact/edit.html | 4 +--- .../views/service-settings/sms-sender/add.html | 4 +--- .../views/service-settings/sms-sender/edit.html | 4 +--- 10 files changed, 17 insertions(+), 30 deletions(-) diff --git a/app/main/forms.py b/app/main/forms.py index 6837be289..799f37e8a 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -1323,7 +1323,7 @@ class ServiceContactDetailsForm(StripWhitespaceForm): class ServiceReplyToEmailForm(StripWhitespaceForm): email_address = email_address(label='Reply-to email address', gov_user=False) - is_default = BooleanField("Make this email address the default") + is_default = govukCheckboxField("Make this email address the default") class ServiceSmsSenderForm(StripWhitespaceForm): @@ -1337,11 +1337,11 @@ class ServiceSmsSenderForm(StripWhitespaceForm): DoesNotStartWithDoubleZero(), ] ) - is_default = BooleanField("Make this text message sender the default") + is_default = govukCheckboxField("Make this text message sender the default") class ServiceEditInboundNumberForm(StripWhitespaceForm): - is_default = BooleanField("Make this text message sender the default") + is_default = govukCheckboxField("Make this text message sender the default") class ServiceLetterContactBlockForm(StripWhitespaceForm): @@ -1351,7 +1351,7 @@ class ServiceLetterContactBlockForm(StripWhitespaceForm): NoCommasInPlaceHolders() ] ) - is_default = BooleanField("Set as your default address") + is_default = govukCheckboxField("Set as your default address") def validate_letter_contact_block(self, field): line_count = field.data.strip().count('\n') @@ -1517,7 +1517,7 @@ class Whitelist(StripWhitespaceForm): class DateFilterForm(StripWhitespaceForm): start_date = DateField("Start Date", [validators.optional()]) end_date = DateField("End Date", [validators.optional()]) - include_from_test_key = BooleanField("Include test keys", default="checked", false_values={"N"}) + include_from_test_key = govukCheckboxField("Include test keys") class RequiredDateFilterForm(StripWhitespaceForm): diff --git a/app/main/views/platform_admin.py b/app/main/views/platform_admin.py index 49e381248..5e86c539b 100644 --- a/app/main/views/platform_admin.py +++ b/app/main/views/platform_admin.py @@ -168,9 +168,11 @@ def platform_admin_services(): # Default to True if the user hasn’t done any filtering, # otherwise respect their choice form.include_from_test_key.data = True + + include_from_test_key = form.include_from_test_key.data api_args = {'detailed': True, 'only_active': False, # specifically DO get inactive services - 'include_from_test_key': form.include_from_test_key.data, + 'include_from_test_key': include_from_test_key, } if form.start_date.data: @@ -184,7 +186,7 @@ def platform_admin_services(): return render_template( 'views/platform-admin/services.html', - include_from_test_key=form.include_from_test_key.data, + include_from_test_key=include_from_test_key, form=form, services=list(format_stats_by_service(services)), page_title='{} services'.format( diff --git a/app/templates/views/platform-admin/services.html b/app/templates/views/platform-admin/services.html index c9e9fb84a..7fd5ce4cf 100644 --- a/app/templates/views/platform-admin/services.html +++ b/app/templates/views/platform-admin/services.html @@ -108,8 +108,7 @@ {% call form_wrapper(method="get") %} {{ textbox(form.start_date, hint="Enter start date in format YYYY-MM-DD") }} {{ textbox(form.end_date, hint="Enter end date in format YYYY-MM-DD") }} - {{ checkbox(form.include_from_test_key) }} -
+ {{ form.include_from_test_key }} {{ govukButton({ "text": "Filter" }) }} {% endcall %} {% endset %} diff --git a/app/templates/views/service-settings/email-reply-to/_verify-updates.html b/app/templates/views/service-settings/email-reply-to/_verify-updates.html index a6cc0d476..1e168ab2e 100644 --- a/app/templates/views/service-settings/email-reply-to/_verify-updates.html +++ b/app/templates/views/service-settings/email-reply-to/_verify-updates.html @@ -55,9 +55,7 @@ hint='This should be a shared inbox managed by your team, not your own email address' ) }} {% if not first_email_address and not existing_is_default %} -
- {{ checkbox(form.is_default) }} -
+ {{ form.is_default }} {% endif %} {{ page_footer('Try again') }} {% endcall %} diff --git a/app/templates/views/service-settings/email-reply-to/add.html b/app/templates/views/service-settings/email-reply-to/add.html index 65135fe26..8e59b885c 100644 --- a/app/templates/views/service-settings/email-reply-to/add.html +++ b/app/templates/views/service-settings/email-reply-to/add.html @@ -24,9 +24,7 @@ safe_error_message=True ) }} {% if not first_email_address %} -
- {{ checkbox(form.is_default) }} -
+ {{ form.is_default }} {% endif %} {{ page_footer('Add') }} {% endcall %} diff --git a/app/templates/views/service-settings/email-reply-to/edit.html b/app/templates/views/service-settings/email-reply-to/edit.html index cdf7e66d9..89fe7e20a 100644 --- a/app/templates/views/service-settings/email-reply-to/edit.html +++ b/app/templates/views/service-settings/email-reply-to/edit.html @@ -29,9 +29,7 @@

{{ page_footer('Save') }} {% else %} -
- {{ checkbox(form.is_default) }} -
+ {{ form.is_default }} {{ page_footer( 'Save', delete_link=url_for('.service_confirm_delete_email_reply_to', service_id=current_service.id, reply_to_email_id=reply_to_email_address_id), diff --git a/app/templates/views/service-settings/letter-contact/add.html b/app/templates/views/service-settings/letter-contact/add.html index 46f10b0da..10ee5998b 100644 --- a/app/templates/views/service-settings/letter-contact/add.html +++ b/app/templates/views/service-settings/letter-contact/add.html @@ -27,9 +27,7 @@ highlight_placeholders=True ) }} {% if not first_contact_block %} -
- {{ checkbox(form.is_default) }} -
+ {{ form.is_default }} {% endif %} {{ page_footer('Add') }} {% endcall %} diff --git a/app/templates/views/service-settings/letter-contact/edit.html b/app/templates/views/service-settings/letter-contact/edit.html index cb1a63b87..4f2be6520 100644 --- a/app/templates/views/service-settings/letter-contact/edit.html +++ b/app/templates/views/service-settings/letter-contact/edit.html @@ -31,9 +31,7 @@ This is currently your default address for {{ current_service.name }}.

{% else %} -
- {{ checkbox(form.is_default) }} -
+ {{ form.is_default }} {% endif %} {{ page_footer( diff --git a/app/templates/views/service-settings/sms-sender/add.html b/app/templates/views/service-settings/sms-sender/add.html index 950d5059f..ba1878a34 100644 --- a/app/templates/views/service-settings/sms-sender/add.html +++ b/app/templates/views/service-settings/sms-sender/add.html @@ -23,9 +23,7 @@ hint='Up to 11 characters, letters, numbers and spaces only' ) }} {% if not first_sms_sender %} -
- {{ checkbox(form.is_default) }} -
+ {{ form.is_default }} {% endif %} {{ page_footer('Save') }} {% endcall %} diff --git a/app/templates/views/service-settings/sms-sender/edit.html b/app/templates/views/service-settings/sms-sender/edit.html index 3e3d543de..3b9069c41 100644 --- a/app/templates/views/service-settings/sms-sender/edit.html +++ b/app/templates/views/service-settings/sms-sender/edit.html @@ -35,9 +35,7 @@

{{ page_footer('Save') }} {% else %} -
- {{ checkbox(form.is_default) }} -
+ {{ form.is_default }} {% if inbound_number %} {{ page_footer('Save') }} {% else %}