From 5ce76b8b3305c606739e0f04e0a0f635b4d4eece Mon Sep 17 00:00:00 2001 From: Ben Thorner Date: Mon, 7 Jun 2021 16:38:58 +0100 Subject: [PATCH] Add property to construct account type string This allows us to start decoupling the form fields from the final, hyphenated string, which we'll do in the next commits. Note that I've also removed the conditional that changes the data of the network field as part of validating it. We shouldn't change data in validations, and having the new property directly above makes it clear there's no need for this code. --- app/main/forms.py | 11 +++++++++-- app/main/views/service_settings.py | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/main/forms.py b/app/main/forms.py index ee04143e5..7f784d0aa 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -2430,11 +2430,18 @@ class ServiceBroadcastNetworkForm(StripWhitespaceForm): thing='a mobile network', ) + @property + def account_type(self): + if self.network_variant.data == f'live-{self.broadcast_channel}-all': + provider = 'all' + else: + provider = self.network.provider_restriction + + return f'live-{self.broadcast_channel}-{provider}' + def validate_network(self, field): if not self.network_variant.data and not field.data: raise ValidationError('Select a mobile network') - if self.network_variant.data == 'all': - field.data = '' class ServiceBroadcastAccountTypeForm(StripWhitespaceForm): diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index 8006e8492..f9ef5cef2 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -381,7 +381,7 @@ def service_set_broadcast_network(service_id, broadcast_channel): return redirect(url_for( '.service_confirm_broadcast_account_type', service_id=current_service.id, - account_type=form.network_variant.data or form.network.data, + account_type=form.account_type, )) return render_template(