Simplify network choice form to use boolean radio

This follows the same pattern as in other forms [1].

[1]: 1b459d6692/app/templates/views/organisations/add-gp-organisation.html (L20)
This commit is contained in:
Ben Thorner
2021-06-07 16:52:36 +01:00
parent 5ce76b8b33
commit ef8cab7fa4
4 changed files with 28 additions and 38 deletions

View File

@@ -2409,11 +2409,6 @@ class ServiceBroadcastNetworkForm(StripWhitespaceForm):
super().__init__(*args, **kwargs)
self.broadcast_channel = broadcast_channel
self.network_variant.choices = [
(f'live-{broadcast_channel}-all', 'All networks'),
('', 'A single network'),
]
self.network.choices = [
(f'live-{broadcast_channel}-ee', 'EE'),
(f'live-{broadcast_channel}-o2', 'O2'),
@@ -2421,9 +2416,12 @@ class ServiceBroadcastNetworkForm(StripWhitespaceForm):
(f'live-{broadcast_channel}-three', 'Three'),
]
network_variant = ServiceBroadcastAccountTypeField(
all_networks = OnOffField(
'Choose a mobile network',
thing='a mobile network',
choices=(
(True, 'All networks'),
(False, 'A single network')
),
)
network = OptionalServiceBroadcastAccountTypeField(
'Choose a mobile network',
@@ -2432,7 +2430,7 @@ class ServiceBroadcastNetworkForm(StripWhitespaceForm):
@property
def account_type(self):
if self.network_variant.data == f'live-{self.broadcast_channel}-all':
if self.all_networks.data:
provider = 'all'
else:
provider = self.network.provider_restriction
@@ -2440,7 +2438,7 @@ class ServiceBroadcastNetworkForm(StripWhitespaceForm):
return f'live-{self.broadcast_channel}-{provider}'
def validate_network(self, field):
if not self.network_variant.data and not field.data:
if not self.all_networks.data and not field.data:
raise ValidationError('Select a mobile network')

View File

@@ -353,23 +353,21 @@ def service_set_broadcast_channel(service_id):
def service_set_broadcast_network(service_id, broadcast_channel):
# only populate old settings when the channel is unchanged
if current_service.broadcast_channel == broadcast_channel:
if current_service.allowed_broadcast_provider == 'all':
provider = current_service.allowed_broadcast_provider
if provider == 'all':
form = ServiceBroadcastNetworkForm(
broadcast_channel=broadcast_channel,
network_variant=(
current_service.live,
current_service.broadcast_channel,
current_service.allowed_broadcast_provider,
),
all_networks=True,
)
else:
form = ServiceBroadcastNetworkForm(
broadcast_channel=broadcast_channel,
network_variant='',
all_networks=False,
network=(
current_service.live,
current_service.broadcast_channel,
current_service.allowed_broadcast_provider
provider,
)
)
else:

View File

@@ -19,9 +19,9 @@
back_link=url_for('.service_set_broadcast_channel', service_id=current_service.id)
) }}
{% call form_wrapper() %}
{% call select_wrapper(form.network_variant, hide_legend=True) %}
{% for option in form.network_variant %}
{{ radio(option, data_target='single-network' if option.data == "" else None) }}
{% call select_wrapper(form.all_networks, hide_legend=True) %}
{% for option in form.all_networks %}
{{ radio(option, data_target='single-network' if option.data == False else None) }}
{% endfor %}
{% endcall %}
{% call conditional_radio_panel('single-network') %}

View File

@@ -5649,18 +5649,12 @@ def test_service_set_broadcast_channel_redirects(
@pytest.mark.parametrize(
'service_mode,broadcast_channel,allowed_broadcast_provider,expected_selected',
[
(
"training",
"test",
"all",
[],
),
(
"live",
"severe",
"all",
[
("All networks", "live-severe-all"),
("All networks", "True"),
],
),
(
@@ -5668,7 +5662,7 @@ def test_service_set_broadcast_channel_redirects(
"government",
"all",
[
("All networks", "live-government-all"),
("All networks", "True"),
],
),
(
@@ -5676,7 +5670,7 @@ def test_service_set_broadcast_channel_redirects(
"test",
"all",
[
("All networks", "live-test-all"),
("All networks", "True"),
],
),
(
@@ -5684,7 +5678,7 @@ def test_service_set_broadcast_channel_redirects(
"test",
"ee",
[
("A single network", ""),
("A single network", "False"),
("EE", "live-test-ee"),
],
),
@@ -5693,7 +5687,7 @@ def test_service_set_broadcast_channel_redirects(
"test",
"o2",
[
("A single network", ""),
("A single network", "False"),
("O2", "live-test-o2"),
],
),
@@ -5702,7 +5696,7 @@ def test_service_set_broadcast_channel_redirects(
"test",
"three",
[
("A single network", ""),
("A single network", "False"),
("Three", "live-test-three"),
],
),
@@ -5711,7 +5705,7 @@ def test_service_set_broadcast_channel_redirects(
"test",
"vodafone",
[
("A single network", ""),
("A single network", "False"),
("Vodafone", "live-test-vodafone"),
],
),
@@ -5720,7 +5714,7 @@ def test_service_set_broadcast_channel_redirects(
"severe",
"vodafone",
[
("A single network", ""),
("A single network", "False"),
("Vodafone", "live-severe-vodafone"),
],
),
@@ -5729,7 +5723,7 @@ def test_service_set_broadcast_channel_redirects(
"government",
"vodafone",
[
("A single network", ""),
("A single network", "False"),
("Vodafone", "live-government-vodafone"),
],
),
@@ -5793,9 +5787,9 @@ def test_service_set_broadcast_network(
expected_result = f'live-{broadcast_channel}-{provider}'
if choice_type == 'network_variant':
data = {'network_variant': expected_result}
data = {'all_networks': True}
else:
data = {'network_variant': '', 'network': expected_result}
data = {'all_networks': False, 'network': expected_result}
client_request.login(platform_admin_user)
client_request.post(
@@ -5817,7 +5811,7 @@ def test_service_set_broadcast_network(
'data',
(
{},
{'network_variant': ''}, # Missing choice of MNO
{'all_networks': ''}, # Missing choice of MNO
),
)
@pytest.mark.parametrize('broadcast_channel', ['government', 'severe', 'test'])